java-collections.sort异常Comparison method violates its general contract!
Posted y酒味i
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java-collections.sort异常Comparison method violates its general contract!相关的知识,希望对你有一定的参考价值。
转载:http://www.tuicool.com/articles/MZreyuv
异常信息
java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:868) at java.util.TimSort.mergeAt(TimSort.java:485) at java.util.TimSort.mergeCollapse(TimSort.java:408) at java.util.TimSort.sort(TimSort.java:214) at java.util.TimSort.sort(TimSort.java:173) at java.util.Arrays.sort(Arrays.java:659) at java.util.Collections.sort(Collections.java:217) ...
原因
JDK7中的Collections.Sort方法实现中,如果两个值是相等的,那么compare方法需要返回0,否则 可能 会在排序时抛错,而JDK6是没有这个限制的。
if (len2 == 0) { throw new IllegalArgumentException("Comparison method violates its general contract!"); }
以上是关于java-collections.sort异常Comparison method violates its general contract!的主要内容,如果未能解决你的问题,请参考以下文章
异常Zipkin server启动 Caused by: java.lang.ClassNotFoundException: com.linecorp.armeria.server.cors.Co
表情存储异常--mybatis抛出异常(java.sql.SQLException: Incorrect string value: 'xF0x9Fx92x94' for co(示例代