其他分享
首页 > 其他分享> > Collections.sort()报Comparison method violates its general contract异常解决方法

Collections.sort()报Comparison method violates its general contract异常解决方法

作者:互联网

在重写Comparator类的compare的方法时,报如下的错误,还没有查到具体原因,因为相同的程序数据量不同,所以不知道是不是数据量太大导致报这个错???


public class ComparatorFloor implements Comparator<DormFloor> {

    public int compare(DormFloor o1, DormFloor o2) {
        if(o1.getSort()!=null && o2.getSort()!=null){
            return o1.getSort().compareTo(o2.getSort());
        }else{
            return o1.getFloorName().compareTo(o2.getFloorName());
        }
    }
    
}

 


java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:899) at java.util.TimSort.mergeAt(TimSort.java:516) at java.util.TimSort.mergeCollapse(TimSort.java:441) at java.util.TimSort.sort(TimSort.java:245) at java.util.Arrays.sort(Arrays.java:1512) at java.util.ArrayList.sort(ArrayList.java:1454) at java.util.Collections.sort(Collections.java:175) at com.chinabnd.dorm.action.ActionFloor.detailread(ActionFloor.java:476) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294) at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)

 

 

标签:sort,Comparison,java,TimSort,contract,util,OgnlRuntime,getSort
来源: https://www.cnblogs.com/wmxblog/p/16529627.html