报错代码
list=list.sort{a,b->if(a.last_update<b.last_update) return -1 else return 1}
报错内容
java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeLo(TimSort.java:777) at java.util.TimSort.mergeAt(TimSort.java:514) at java.util.TimSort.mergeForceCollapse(TimSort.java:457) at java.util.TimSort.sort(TimSort.java:254) at java.util.Arrays.sort(Arrays.java:1512) at java.util.ArrayList.sort(ArrayList.java:1460) at java.util.Collections.sort(Collections.java:175)
解决方案
list=list.sort{a,b->if(a.last_update<b.last_update) return -1 else if(a.last_update<b.last_update) return 0 else return 1}
返回值会需要是 1 , -1, 0 这三个值