Java generic: can generic extend another generic class?
Here, this is my problem. I have three summary classes, all of which are general. I want something like this:
public abstract class AbstracOne< T extends AbstractTwo< K extends AbstractThree<K> >>>
This doesn't work, I get the following error (in the second extension):
Syntax error for token 'extends', expected
However, if I use the following code, it is working:
public abstract class AbstracOne< T extends AbstractTwo< ? extends AbstractThree<?> >>>
So, what's the difference between using K and?
thank you very much
Solution
Input parameter vs type parameter
You can clear the difference by reading this excellent FAQ by Angelica Langer
Generic classes have type parameters that are replaced with type parameters when you use generic classes
Type parameters can have constraints A type parameter can be a fully qualified type or a previously defined type parameter
Therefore, if you have defined K, you can use K. you can also add constraints when defining constraints
public abstract class AbstractOne<K extends AbstractThree<K>,T extends AbstractTwo<K>>
Good luck