mutable fields for objects in a Java Set

后端 未结 4 1775
悲&欢浪女
悲&欢浪女 2020-12-16 18:18

Am I correct in assuming that if you have an object that is contained inside a Java Set<> (or as a key in a Map<> for that matter), any fields that are used to determi

4条回答
  •  攒了一身酷
    2020-12-16 18:27

    That is correct, it can cause some problems locating the map entry. Officially the behavior is undefined, so if you add it to a hashset or as a key in a hashmap, you should not be changing it.

提交回复
热议问题