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;
}
});这样修改后就可以了。

相关文章:

  • 2021-09-02
  • 2022-12-23
  • 2021-10-29
  • 2021-10-24
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2021-11-19
  • 2021-12-09
  • 2021-09-17
  • 2021-06-14
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
相关资源
相似解决方案