根据
the JLS(Java语言规范):
The notion of subsignature is designed to express a relationship between two methods whose signatures are not identical, but in which one may override the other. Specifically, it allows a method whose signature does not use generic types to override any generified version of that method.
此代码基于JLS示例:
interface CollectionConverter {
List toList(Collection c);
void fooMethod(Class> c);
Comparable method3(E e);
Comparable method4(U u);
}
class Overrider implements CollectionConverter {
@Override
public List toList(Collection c) {
return null;
}
@Override
public void fooMethod(Class c) {
}
@Override
public Comparable method3(Object o) {
return null;
}
@Override
// compile error, have to change Object to Integer
public Comparable method4(Object u) {
return null;
}
}
根据JLS,我理解为什么前三种方法运行良好,但我无法弄清楚为什么method4有这个编译错误:
The method method4(Object) of type Overrider must override or implement a supertype method.