Are two Java objects with same hashcodes not necessarily equal?

后端 未结 9 2165
礼貌的吻别
礼貌的吻别 2020-11-27 06:34

I understand why providing same hashcode for two equal (through equals) objects is important. But is the vice versa true as well, if two objects have same hash

9条回答
  •  一个人的身影
    2020-11-27 07:02

    If two objects have the same hashcode then they are NOT necessarily equal. Otherwise you will have discovered the perfect hash function.

    But the opposite is true: if the objects are equal, then they must have the same hashcode.

提交回复
热议问题