Why is equals not mandatory to implement in java.util.Comparator?

后端 未结 2 1629
醉梦人生
醉梦人生 2021-02-02 16:04

Either in Javadoc as well as the code itself, Comparator interface defines:

 int compare(T o1, T o2);
 boolean equals(Object obj);

But then thi

2条回答
  •  庸人自扰
    2021-02-02 16:45

    Beczuse every object already implements equals().

    In reality specifying equals() again in the Comparator interface definition accomplishes precisely nothing except giving a chance to document the contract and its relationship with compareTo().

提交回复
热议问题