I've seen the HashCodeBuilder of Apache Commons Lang and the Eclipse hashCode() generation. I have to say that Eclipse's hashCode() is very ugly, but is it better to use as HashCodeBuilder in terms of performance (because an extra object creation is needed for the builder)?
I'd also like to know what you think about the equals() generation and Commons Lang's EqualsBuilder.
And if you got even better solutions, please post them too :)
The HashCodeBuilder
is much slower than just writing your own hash function. It uses reflection to iterate over each field. If you are calling this method frequently, you may see a performance hit, which may or may not be tolerable for your situation.
The hashCode
function generated by eclipse uses prime numbers to help create a better hash function. Why use a prime number in hashCode? has some details on why that is