我知道实现/覆盖 equals()
也没有覆盖 hashCode()
违反了 equals/hashCode 契约。
但是如果一个类只实现 hashCode()
呢?而不是equals()
?
最佳答案
如果一个类只有 hashCode()
那么这不是问题:equal()
的对象将具有相同的 hashCode()
>.
这是因为 equals()
将回退到 Object
的实现,即 identity,这当然会给出相同的结果hashCode()
关于java - hashCode() 没有 equals()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48634939/