I recently have to override the equals
and hashCode
methods in Java. I hence looked for a fast and efficient way to compute hash codes.
Java developers seem to aggree on the following method :
int hash = 23;
hash = hash * 37 + paramOne;
hash = hash * 37 + paramTwo;
// And so on...
It might be simple arithmetic but I don't really get it. What are the garantees ? What are the corner cases ? Is there a better (rather simple) way to do it ?
Thank you !