Comparison method violates its general contract异常信息问题处理
今天采用Collections.sort 来对文件进行排序,出现
Comparison method violates its general contract 异常,
找了好久,才发现是实现接口Comparator 的类有问题,
在compare中没有处理好两个比较的对象相等的情况
最好也捕获下异常
public int compare(T lhs, T rhs); 即 lhs == rhs 时,返回值不能是0
@Override
public int compareTo(Wind another) {
// TODO Auto-generated method stub
if(another==null)
return 1;
else if(this==null)
return -1;
if(this==another)
return 1;
if(this==another)
return 1;