public abstract class Abc<T> {
public abstract void f1(T a);
}
abstract class Def<T> extends Abc {
@Override
public void f1(T a) {
System.out.print("f");
}
}
This gives the following error: " method does not override or implement a method from a supertype"
What is wrong here?
Your class definition needs to indicate that you're extending the parent class generically.
abstract class Def<T> extends Abc<T>
Otherwise, the compiler more or less assumes that you're extending Abc<object>
, so the method signature that includes a T
parameter doesn't match the one from the parent class (since it's using a different T
parameter).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With