I'm doing an experience, trying to override a Method of a Generic Class, in this way:
public class MyGenFun<T extends CharSequence> extends Do<String>{
public void doX(T s){
System.out.println("in CHILD");
}
public static void main (String ...a){
MyGenFun<String> x = new MyGenFun<>();
x.doX("Test"); /// LINE 1
}
}
class Do<A>{
public void doX(A a){
System.out.println("in Super");
}
}
Why I can't? The compile error is
yGenFun.java:15: error: reference to doX is ambiguous, both method doX(A) in Do and method doX(T) in MyGenFun match x.doX("Test"); ^ where A,T are type-variables: A extends Object declared in class Do T extends CharSequence declared in class MyGenFun 1 error
If I comment the "Line 1", I can compile the code. So I think I am overriding correctly.