gpt4 book ai didi

java - 为什么,如果两个对象根据 equals 不相等,则不需要返回不同的 hashCode 值?

转载 作者:行者123 更新时间:2023-11-29 10:06:53 24 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
In Java, why must equals() and hashCode() be consistent?
Why hashCode() can return the same value for different objects in java?

在JAVA API中我们可以看到

If two objects are not equal according to equals, they are not required to return different hashCode values.

为什么会这样?

如果根据equals,两个对象不相等,那么应该要求返回不同的hashCode值吧?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com