Al Wld Al Wld - 1 month ago 12
Java Question

Nested generic subtyping

I am trying to do something like this:

public class MyClass <T extends AbstractClass<K extends ConcreteClass>>


I get an
Unexpected bound
error for K extends GenericJson, and I am not sure why.

Any help would be appreciated.

Thanks

Answer

The syntax to use is just a little different:

public class MyClass <K extends ConcreteClass, T extends AbstractClass<K>>

Or, if you don't care about K:

public class MyClass <T extends AbstractClass<? extends ConcreteClass>>