mercredi 21 octobre 2020

Random integer as hashCode

Is it a good idea to generate a random number in the constructor and return this value from hashCode method? There is a chance for collisions, but this applies when writing your own hashCode method. So what are the drawbacks? When using this object in a HashMap it will be stored with the random number as a hash and then retrieved by the same. If there are collisions they will be resolved by equals.




Aucun commentaire:

Enregistrer un commentaire