Transitive nature of equals method

前端 未结 4 1186
一个人的身影
一个人的身影 2020-12-09 15:23

The contract for equals(object) method specifies 4 properties to follow: Reflexive, Symmetric, Transitive and Consistent. While I understand the danger of not f

4条回答
  •  佛祖请我去吃肉
    2020-12-09 16:17

    Consider Object a == b == c with a != c ( non transitive equality )

    First problem would be hashcode() contract which requires that hashcodes are equal if objects are equal. And you will be able to add a and c to the same set - this can lead to subtle problems in unexpected places

提交回复
热议问题