我想实现我的排序方法,这需要一个通用的E[]
作为参数,在我int[]
。我收到的错误:方法(E [])是不适用的参数(INT [])
The method sort(E[]) in the type HeapSort is not applicable for the arguments (int[]).
我的代码如下:
public <E extends Comparable<E>> void sort(E[] array){
//my code
}
public static void main(String[] args){
int[] arr = new int[30];
for(int rep = 0; rep < arr.length; rep++){
arr[rep] =(int)(Math.random() * 100 + 0);
}
System.out.println("The unsorted Array: ");
System.out.println(sort(arr).toString());
}
任何想法,为什么我得到这个错误?所有帮助赞赏!谢谢!
'的System.out.println(排序(ARR)的ToString());'是无效的,因为这'排序()'方法返回'void'。 – MikeCAT
错误消息已足够清楚。你对此不了解什么? – Raedwald