定义一个类似的类
public class MyRandomList<T extends Comparable>{
List<T> randomList;
}这意味着我们可以创建一个MyRandomList实例,其中包含实现可比较的任何类。
MyRandomList<ComparableStudent> l = new MyRandomList<ComparableStudent>();哪里
public class ComparableStudent implements Comparable<ComparableStudent>{
}语法不应该是<T implements Comparable>吗?
还是我理解了Java的一些根本错误?
发布于 2019-05-25 09:43:03
简单地说: Java在为泛型类型参数定义边界时没有区分接口和类。extends用于接口和类类型,这使得表达the bound direction (从主帖子上的Sambit注释添加的链接)更加流线型。
https://stackoverflow.com/questions/56303599
复制相似问题