public int compare(File f1, File f2) {
try {
Date fileDateTime1 = InterimUtil.extractDate(InterimUtil.fileDateFormat, f1);
Date fileDateTime2 = InterimUtil.extractDate(InterimUtil.fileDateFormat, f2);
if (fileDateTime1.getTime() > fileDateTime2.getTime()) {
return 1;
}
return -1;
} catch (Exception e) {
NGVSInterimFileGenerator.LOGGER.severe("Error occured in comparator" + e.getMessage());
}
return -1;
}
};
Arrays.sort(files, fileModTimeComp);
执行上述代码时出错。上面的代码正在发出以下错误。
java.lang.IllegalArgumentException:比较方法违反了它 总合同!在java.util.TimSort.mergeHi(TimSort.java:899)at java.util.TimSort.mergeAt(TimSort.java:516)at java.util.TimSort.mergeCollapse(TimSort.java:441)at java.util.TimSort.sort(TimSort.java:245)at java.util.Arrays.sort(Arrays.java:1438)