How do we decide on the best implementation of hashCode()
method for a collection (assuming that equals method has been overridden correctly) ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use the reflection methods on Apache Commons EqualsBuilder and HashCodeBuilder.
When combining hash values, I usually use the combining method that's used in the boost c++ library, namely:
This does a fairly good job of ensuring an even distribution. For some discussion of how this formula works, see the StackOverflow post: Magic number in boost::hash_combine
There's a good discussion of different hash functions at: http://burtleburtle.net/bob/hash/doobs.html