When I try to override a method that takes a List<String>
, I get the following compile error.
Multiple markers at this line:
- The methodgetname(List<Integer>)
of typechild
must override or implement a supertype method
- Name clash: The methodgetname(List<Integer>)
of typechild
has the same erasure asgetname(List<String>)
of typeparent
but does not override it
I was under the impression, that due to erasure, a method that takes a List<String>
and a subclass method that takes a List<Integer>
would be considered as overridden, because the signature of both methods are same after erasure.
Here is the definition for method signature that involves erasure.
I do not understand why this error comes and what exactly it means.
My code is below:
class parent {
public void getname(List<String> num) {
System.out.printf("parent class: %s",num);
}
}
class child extends parent {
@Override // here is the compile error
public void getname(List<Integer> num) {
System.out.printf("child class: %s",num);
}
}