Vote count: 0
I have the following hashcode method of Object class being overridden in the base class
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
It performs a right shift of id by 32 bits and then XORs by itself. Then, cast the result into an int following by addition with result (initialized to 1). Finally, we assign the result to result.
My understanding is that if we use op1 >>> op2, then all the bits of op1 are shifted to the right by op2 and left bits are padded with 0s (unlike >> where the left bits are padded with the highest sign bit on the left side).
asked 38 secs ago
Purpose of the following hashcode function
Aucun commentaire:
Enregistrer un commentaire