Clearly, this approach is a pain but the solution is easy: Never use a mutable object type as a key in a HashMap.
很显然,这种方法很糟糕,但是解决方法也很简单:永远不要将可变对象类型用作hashmap中的键。
This is usually not a problem in practice — it is not common practice to use a mutable object like a List as a key in a HashMap.
实践过程中这通常不是问题——我们并不经常使用象List这样的可修改对象做为hashmap中的关键字。
Cases where an aliased mutable object gets unexpectedly modified can crop up in a number of subtle and surprising ways, and debugging them can be extremely difficult.
有别名的可变对象被意外修改的情况会以许多微妙且令人惊奇的方式突然出现,并且调试起来相当困难。
This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes.
当默认值是一个可变对象,诸如链表、字典或大部分类实例时,会产生一些差异。
This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes.
这使得当默认值是可变对象时会有所不同,比如列表、字典或者大多数类的实例。
Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key.
如果元组中只包含字符串和数字,它可以做为关键字,如果它直接或间接的包含了可变对象,就不能当做关键字。
There are some other issues such as small mutable object creation, such as Rectangle, Point etc, these objects usually cannot be re-used due to synchronization consideration.
一些其他的问题来源于小的可变对象的创建,如Rectangle,Point,这些对象基于同步的考虑通常不可重用。
There are some other issues such as small mutable object creation, such as Rectangle, Point etc, these objects usually cannot be re-used due to synchronization consideration.
一些其他的问题来源于小的可变对象的创建,如Rectangle,Point,这些对象基于同步的考虑通常不可重用。
应用推荐