Why would one add a constant to hashCode()? [duplicate]
问题 This question already has answers here : Why does Java's hashCode() in String use 31 as a multiplier? (13 answers) Closed 2 years ago . I'm new to Java, and I've recently learned about hashCode() . On the wikipedia article about Java hashCode(), there is the following example of a hashCode() method: public class Employee { int employeeId; String name; Department dept; // other methods would be in here @Override public int hashCode() { int hash = 1; hash = hash * 17 + employeeId; hash = hash *