“比较方法违反了其总合同”,但我不知道哪个合同违反了

时间:2014-08-14 06:01:10

标签: java

我的代码如下:

private Comparator<Task> comparator = new Comparator<Task>() {
    @Override
    public int compare(Task lhs, Task rhs) {
        if (lhs.isCompleted() != rhs.isCompleted()) {
            if (lhs.isCompleted()) {
                return 1;
            } else {
                return -1;
            }
        } else {
            if (lhs.isMarked() != rhs.isMarked()) {
                if (lhs.isMarked()) {
                    return -1;
                } else {
                    return 1;
                }
            } else {
                lTime.set(lhs.getCreatedTime());
                rTime.set(rhs.getCreatedTime());
                return Time.compare(lTime, rTime);
            }
        }
    }
}

它抛出java.lang.IllegalArgumentException: Comparison method violates its general contract!,我的问题是,我的方法违反了哪个合同?谢谢!

0 个答案:

没有答案