They provide a mutable wrapper for otherwise immutable object references.
它们为那些用其他方式不可改变的对象引用提供了一个可改变的包装器。
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 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.
这使得当默认值是可变对象时会有所不同,比如列表、字典或者大多数类的实例。
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.
有别名的可变对象被意外修改的情况会以许多微妙且令人惊奇的方式突然出现,并且调试起来相当困难。
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,这些对象基于同步的考虑通常不可重用。
Unearthing tidbits often involves some complexity, however, like discovering that you can have your way with HashMap, just as long as you never use a mutable object type as its key.
但是发掘这些有用之物可能有点复杂,比如只要您不将可变对象类型作为键,您就可以用自己的方式使用 HashMap。
Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies.
这通常意味着要复制包含正在被复制对象的内部“深层结构”的所有可变对象,并使用对副本的引用替换对这些对象的引用。
Methods you call shouldn't depend on the mutable state of any object and should return fully reproducible and predictable results.
您所调用的方法不应依赖于任何对象的易变状态,而应返回可再生产、可预测的结果。
For example, a user is a mutable entity, but you might use an immutable value object to represent the user's address, just changing the address that you point to for the user if he or she moves.
例如,虽然用户是可变实体,但是您可以使用不可变值对象来表示用户的地址,如果用户移动了位置,那么只需为该用户更改您所指向的地址。
When used as constructor parameters, the mutable or immutable variables specified will be initialized when an object is instantiated.
当作为构造函数参数时,这些可变或者不可变的变量会在一个对象被实例化的时候被初始化。
XMLGregorianCalendar objects are mutable, and therefore you can simply set any of the date or time fields directly on the object.
XMLGregorianCalendar对象是可以修改的,因此能够直接设置对象的日期或时间字段。
XMLGregorianCalendar objects are mutable, and therefore you can simply set any of the date or time fields directly on the object.
XMLGregorianCalendar对象是可以修改的,因此能够直接设置对象的日期或时间字段。
应用推荐