【发布时间】:2016-02-29 09:22:25
【问题描述】:
我正在尝试在我的int[] 上实现我的排序方法,该方法将通用E[] 作为参数。我收到错误:
HeapSort 类型中的方法 sort(E[]) 不适用于参数 (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(sort(arr).toString());无效,因为此sort()方法返回void。 -
错误信息已经够清楚了。你有什么不明白的?