【发布时间】:2022-01-24 16:57:56
【问题描述】:
我有这些类(在不同的文件中):
public class Student implements Comparable<Student> {
...
}
public class Application {
public static <T> T getMax (Vector<Comparable<T>> v){
}
}
我尝试解决这个问题:
public static void main(){
Vector<Student> v = new Vector();
v.add(new Student());
v.add(new Student());
Application app = new Application();
app.getMax(v);// <--- error is here
}
但我得到了错误:
类型Application中的getMax(Vector
)方法是 不适用于参数(向量)
我错过了什么?
【问题讨论】:
-
"
public static <T> T getMax (Vector<Comparable<T>> v){" 看起来很奇怪。我建议使用public static <T extends Comparable<T>> T getMax (Vector<T> v){。 --- "Vector<Student> v = new Vector();" - Don't use raw types。 ---Vectors 是专门为并发设计的。如果我们不需要这个,我们可以使用List。
标签: java generics inheritance vector