我不断收到一条消息,告诉我运营商<
对于T,T
类型未定义。这发生在查找通用ArrayList中的最小值
if(index<lowest)
我该如何去修改我的程序,以便我可以使用泛型方法获取数组列表的最小值和最大值?
package p07;
import java.util.ArrayList;
public class MyList<T extends Number> {
private ArrayList<T> l;
public MyList(ArrayList<T> l) {
this.l=l;
}
public void add(T x) {
l.add(x);
}
public static <T> void smallest(ArrayList<T> l) {
T lowest=l.get(0);
for(T index:l) {
if(index<lowest) {
}
}
}
}
你不能使用Math.max()吗? – Pavan
我不相信我们被允许使用它 – Matt
然后,您可能需要使用自己的可比较的接口实现并使用api,如Collections.min/Collections.max – Pavan