Object[] a = {new Integer(1),new String("abc")};
Collections.sort(Arrays.asList(a));//error

The generic method sort(List<T>) of type Collections is not applicable for the arguments
(List<Object>). The inferred type Object is not a valid substitute for the bounded parameter <T extends Comparable<?
super T>>

 

要能使用sort方法List中的数据类型必须要实现了Comparable接口;Object不行

 

Object[] a = {new Integer(1),new String("abc")};
Collections.sort(Arrays.asList(a),new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
// TODO Auto-generated method stub
return 0;
}
});这样修改后就可以了。