Let's say I have two classes. Each class has one parameter. Parameter of first class bounded to a second class and vice versa. But there is an additional requirement. This parameter must also be parametrized by class itself. This is better to be explained by example:
public class Class1<T extends Class2<Class1>> {
...
}
public class Class2<T extends Class1<Class2>> {
...
}
However, this construction doesn't work. Compiler tells Type parameter Class2 is not within its bound
. This is perfectly understandable, because compiler unable to resolve this endless recursion.
But I'd like to know is there any elegant way to get what want by means of generic?