why does my compare method throw exception — Comparison method violates its general contract!

后端 未结 7 1733
别那么骄傲
别那么骄傲 2020-11-30 12:49

Why does this code

public class SponsoredComparator implements Comparator {

    public boolean equals(SRE arg0, SRE arg1){
        return arg0.g         


        
7条回答
  •  盖世英雄少女心
    2020-11-30 12:57

    The contract between equals() and compareTo() is that when equals() returns true, compareTo() should return 0 and when equals() is false compareTo should return -1 or +1.

    BTW: I assume your compare() method is not called very often as the debug messages will use up a signficiant amount of CPU and memory.

提交回复
热议问题