在Java中编写哈希函数的最佳做法是什么? [英] What is a best practice of writing hash function in java?
问题描述
我想知道在java中编写#hashCode()方法的最佳做法是什么。
好的描述可以在这里找到。这是一个很好的解决方案吗?
一个很好的参考,用于实现 hashCode()
在有效的Java 。在了解生成良好散列函数的理论后,您可以检查 HashCodeBuilder ,它实现了本书中描述的内容。从文档:
这个类可以为任何类构建一个很好的hashCode
方法。它
遵循约书亚布洛克书
Effective Java中规定的规则。
编写一个好的hashCode方法实际上是相当困难的
。这个类
旨在简化过程。
I'm wondering what is the best practice for writing #hashCode() method in java. Good description can be found here. Is it that good?
A great reference for an implementation of hashCode()
is described in the book Effective Java. After you understand the theory behind generating a good hash function, you may check HashCodeBuilder from Apache commons lang, which implements what's described in the book. From the docs:
This class enables a good hashCode method to be built for any class. It follows the rules laid out in the book Effective Java by Joshua Bloch. Writing a good hashCode method is actually quite difficult. This class aims to simplify the process.
这篇关于在Java中编写哈希函数的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!