我使用简单的比较器并得到异常并且不知道该怎么做
这就是我所说的:
try {
Collections.sort(this.closePositions, new PositionComperator());
}
catch(Exception e) {
e.printStackTrace();
}
这是比较器:
public class PositionComperator implements Comparator<DataResponse> {
@Override
public int compare( DataResponse pos1, DataResponse pos2) {
if (pos1.openTime >= pos2.openTime) {
return 1;
}
else {
return -1;
}// returning 0 would merge keys
}
}
这是一个例外:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at GTTask.RefreshIdentityHistory.call(RefreshIdentityHistory.java:59)
at GTTask.RefreshIdentityHistory.call(RefreshIdentityHistory.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)