Sometimes I need to implement an obj's hashCode() method by combining the hashCodes of its several instance members. For example, if the combinational obj has members a, b, and c, I often see ppl implement it as
int hashCode(){
return 31 * 31 * a.hashCode() + 31 * b.hashCode() + c.hashCode();
}
Where does this magic number 31 come from? Is it the length of 4-bytes or just a prime number?
Is there any other preferred/standard way of implementing hashCode()?