How does Java HashMap store entries internally

前端 未结 3 527
生来不讨喜
生来不讨喜 2020-12-10 15:00

Say you have a key class (KeyClass) with overridden equals, hashCode and clone methods. Assume that it has 2 primitive fields, a String (name) and an int (id).

Now y

3条回答
  •  春和景丽
    2020-12-10 15:30

    If you change the entry but not the hashCode, you are safe. For this reason it is considered best practice to make all fields in the hashCode, equals and compareTo, both final and immutable.

提交回复
热议问题