I have overwritten the hashcode-method for my class (with one instance variable named "id").
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
What exactly happens in the last line? There should be two different cases:
Case 1: id == null , which means that result should be equal to 31.
Case 2: id != null , which means that result should be equal to 31 + id.hashCode();
I do not understand the two cases (or i am not even sure if they are correct). And what is the point of the prime number anyway? Why should we assign the null reference to 31?