Can somebody explain below code line by line or can somebody give me simplified version. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

4th May 2019, 4:42 PM
stephen haokip
stephen haokip - avatar
1 Answer
+ 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
4th May 2019, 6:36 PM
Denise Roßberg
Denise Roßberg - avatar