Yes, in Google you can find the article. We deal with hashCode () and equals () , where the rules for overriding hashCode() and equals() are described in a completely accessible language. In extreme cases, you can take the same Bloch with its Java philosophy and see these rules there. It's not about that. The rules are clear to me.
This is not clear:
@Override public int hashCode() { int hash = 37; hash = hash * 17 + str1.hashCode(); hash = hash * 17 + str2.hashCode(); hash = hash * 17 + num; return hash; } In different examples, some numbers are taken as a basis. In this example, 37 and 17 are taken.
There are a lot of such examples on the Internet, but in each of them the numbers are different. In one example, the following construction was encountered:
@Override public int hashCode() { int hash = new Random().nextInt(255); hash = hash * 255 + dozer.hashCode(); hash = hash * 255 + tank.hashCode(); return hash; } What totally confused me. How to correctly redefine the hash code?
In this regard, a number of questions:
Should I use any numbers at all?
Does it matter what number to choose? Or is it some kind of "agreement" within the team when developing a product?
Are there any restrictions on the choice of starting numbers?
Why does the hash need to be multiplied by itself each time (I understand the addition of the object field hashes to me)?