I have a vector class with hashCode() implemented. It wasn\'t written by me, but uses 2 prime numbers by which to multiply the 2 vector components before XORing them. Here i
That's the normal practice. It looks pretty reasonable to me. If you're using Eclipse, you should find that it can generate equals
and hashCode
for you—just check the Source menu. It will do the same thing—enumerate your fields and create an equals
method that checks all of them, then choose n prime numbers and do what you've done to create a hashCode
method.