Changing hashCode of object stored in hash-based collection

前端 未结 5 1303
孤独总比滥情好
孤独总比滥情好 2021-01-15 12:02

I have a hash-based collection of objects, such as HashSet or HashMap. What issues can I run into when the implementation of hashCode()

5条回答
  •  猫巷女王i
    2021-01-15 12:43

    Don’t change hashcode of elements in hash based collection after put.

    Many programmers fall into the pitfall. You could think hashcode is kind of address in collection, so you couldn’t change address of an element after it’s put in the collection.

提交回复
热议问题