CoreJava.ch5.1.3
JDK1.4
interface A {
List getList();
}
class B implements A {
public ArrayList getList() {
return null;
}
}
error:
- The return type is incompatible with A.getList()
- implements A.getList
JDK5
没有编译错误。
本文探讨了在 JDK1.4 和 JDK5 中,对于接口中返回类型为 List 的方法的不同实现方式。在 JDK1.4 中直接返回 null 会导致编译错误,而在 JDK5 中则没有此限制。
1690

被折叠的 条评论
为什么被折叠?



