Reprint: HTTP://WWW.TUICOOL.COM/ARTICLES/MZREYUV
Exception information
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) ...
Reason
In the implementation of the Collections.sort method in JDK7, if two values are equal, then the Compare method needs to return 0, otherwise it may throw a wrong order, and JDK6 is not.
if (Len2 = = 0) {thrownew illegalargumentexception ("Comparison method violates its general Contract! " );}
Java-collections.sort anomaly comparison method violates its general contract!