我试图弄清楚如何比较 T[] 数组中的两个项目,这就是我所拥有的:
public static <T extends Comparable< ? super T>> T getLargest(T [] a, int low,
int high){
if(low>high)
throw new IllegalArgumentException();
T[] arrCopy = (T[]) new Object[high-low];
for(int i=low;i<high;i++){
if(a[i].compareTo(a[i-1])>0)
arrCopy[i]=a[i];
else
arrCopy[i]=a[i+1];
}
return arrCopy[0];
}
然后我得到错误:Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;
关于如何解决这个问题的任何想法?