根据
thejls(Java语言规格) :
thenotionofsubsignatureisdesignedtoexpressarelationshipbetweentwomethodswhosesignaturesarenotidentical,butinwhichonemayovererrer itallowsamethodwhosesignaturedoesnotusegenerictypestooverrideanygenerifiedveride
此代码基于JLS示例。
接口收集转换器{
列表(collection c;
语音文档(类c;
比较方法3 (ee;
可比较方法4 (uu;
}
classoverriderimplementscollectionconverter {
@Override
publiclisttolist(collectionc ) {
返回空值;
}
@Override
公共语音格式(类c ) {
}
@Override
publiccomparablemethod3(objecto ) {
返回空值;
}
@Override
//compile error,have to change Object to Integer
publiccomparablemethod4(objectu ) {
返回空值;
}
}
根据JLS的说法,我理解前三种方法工作正常的原因,但不知道method4为什么会有此编译错误:
themethodmethod4(对象) oftypeoverridermustoverrideorimplementasupertypemethod。