I'm wondering what is the best practice for writing #hashCode() method in java. Good description can be found here. Is it that good?
question from:https://stackoverflow.com/questions/2738886/what-is-a-best-practice-of-writing-hash-function-in-javaI'm wondering what is the best practice for writing #hashCode() method in java. Good description can be found here. Is it that good?
question from:https://stackoverflow.com/questions/2738886/what-is-a-best-practice-of-writing-hash-function-in-javaA 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.