关于IllegalArgumentException: Comparison method violates its general contract!

最近遇到了IllegalArgumentException: Comparison method violates its general contract!  google了半天终于找到了解决办法,有以下三种:

(1) 更改Comparator内部实现,确保排序的逻辑满足以下条件:

a) sng(compare(x,y)) == -sgn(compare(y,x));

b) 如果(compare(x,y) > 0) && (compare(y,z) > 0),那么有 compare(x,z) > 0.

c) compare(x,y) == 0, 意味着对任意的z: sgn(compare(x, z))==sgn(compare(y, z))成立

(2) Java 7 预留了一个接口便于用户继续使用Java 6的排序算法,在启动参数中添加

java.util.Arrays.useLegacyMergeSort=ture;

(3) 手动捕获IllegalArgumentException.


文章出处:lifebackup,作者:Superpippo
链接: http://www.lifebackup.cn/timsort-java7.html

你可能感兴趣的:(Java,Android)