在Effective Java Item 9中(当你覆盖equals时总是覆盖hashCode)
Many classes in the Java platform libraries,such as String,
Integer,and Date,include in their specifications the exact value
returned by their hashCode method as a function of the instance value.
This is generally not a good idea,as it severely limits your ability
to improve the hash function in future releases.
这是什么意思 ?
最佳答案
这意味着您无法在更高版本的代码中重写散列函数以获得更好的散列属性.例如,String.hashCode()函数很快……但不是很好.但它不能再被更改了,因为哈希代码已经指定,并且人们已经在自己的代码中依赖于该实现.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。