我想實現我的排序方法,這需要一個通用的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