首页 > 编程知识 正文

泛型的使用,java中的泛型怎么用

时间:2023-05-04 00:22:55 阅读:11316 作者:633

根据

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。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。

  •  标签:  
  • java