package compareble;
public class testtt {
public static void main(String[] args) {
stu[] arr=new stu[2];
arr[0]=new stu();
arr[1]=new stu();
sort<stu> sort =new sort<stu>();
System.out.println(sort.selsort(arr));
}
}
package compareble;
public class sort<T> {
public int selsort(Comparable<T>[] list){
return list[0].compareTo((T) list[1]);
}
}
package compareble;
public class stu implements Comparable<stu>{
@Override
public int compareTo(stu o) {
return -400;
}
}
请问在sort方法中调用compareTo方法时,为什么调用者list【0】不用强制类型转换为(T),然而形式参数list【1】中却要强制转换为(T)list【1】,想了很久想不明白,求java大佬解惑