0
Can somebody explain below code line by line or can somebody give me simplified version.
} @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } Why is prime = 31. And result = 1. Thank q
1 Respuesta
+ 1
Maybe this helps you:
https://www.quora.com/Why-are-prime-numbers-used-for-constructing-hash-functions
result = 31 * 1 + //a shorten if statement
if(name == null)
result = 31 * 1 + 0
else
result = 31 * 1 + name.hashCode();
I am not really sure at this point but I think it is a recursive function (it calls itself, until name == null).
About hash function:
https://en.m.wikipedia.org/wiki/Hash_function