本帖最后由 小黑子 于 2014-10-8 17:16 编辑
就想试试Collections中的sort()好不好用,结果出来一堆从来没见过的错误提示:'(,快吓尿了- import java.util.*;
- import java.util.Collections.*;
- class CollectionsDemo
- {
- public static void main(String[] args)
- {
- ArrayList<String> al = new ArrayList<String>();
- al.add("xiao");
- al.add("cheng");
- al.add("aa");
- al.add("kkkkkkk");
-
- sortDrill(al);
- }
- public static <T> void sortDrill(ArrayList<T> list)
- {
- Collections.sort(list);
- for(int i =0;i<list.size();i++)
- {
- System.out.println(list.get(i));
- }
- }
- }
复制代码 编译后提示如下:
D:\CODE\JAVA\review\day17>javac CollectionsDemo.java
CollectionsDemo.java:20: error: no suitable method found for sort(ArrayList<T#1>
)
Collections.sort(list);
^
method Collections.<T#2>sort(List<T#2>) is not applicable
(inference variable T#2 has incompatible bounds
equality constraints: T#1
upper bounds: Comparable<? super T#2>)
method Collections.<T#3>sort(List<T#3>,Comparator<? super T#3>) is not appli
cable
(cannot infer type-variable(s) T#3
(actual and formal argument lists differ in length))
where T#1,T#2,T#3 are type-variables:
T#1 extends Object declared in method <T#1>sortDrill(ArrayList<T#1>)
T#2 extends Comparable<? super T#2> declared in method <T#2>sort(List<T#2>)
T#3 extends Object declared in method <T#3>sort(List<T#3>,Comparator<? super
T#3>)
1 error
|