You cannot change the number of type parameters in an overridden method. For your case, overriding is clearly not the return type. But even if the return types were the same, your method will still not override the equivalent, since you have fewer type parameters in the intended overridden method.
From JLS - Method Signature :
Two methods have the same signature if they have the same name and argument types.
Two declarations of a method or constructor, M and N, have the same argument if all of the following conditions are true:
- They have the same number of formal parameters (possibly zero)
- They have the same number of type parameters (possibly zero)
Thus, even the following code will not work:
interface Demo { public <S, T> void show(); } class DemoImpl implements Demo { @Override public <T> void show() { }
Because the show()
method in the class does not override the equivalent using the method in the interface, due to fewer type parameters.
So, you have to make sure that the method signature is exactly the same as indicated in this JLS section (same name, same number and type of parameters (including type parameters), type of the returned sharing option).
source share