Thus, you should never have a no-argument constructor for an immutable class.
因此,您永远都不该为一个不可变类提供一个无参数的构造函数。
An immutable class that meets the previous requirements appears in Listing 1.
清单1中列出了一个满足上述要求的不可变类。
Using this style of code is a strong visual indicator that it's an immutable class.
这种代码风格的使用从视觉上给出了一种强烈的指示:该类是一个不可变类。
The following example shows two ways to implement an immutable class that has auto-implemented properties.
下面的示例演示两种方法来实现具有自动实现属性的不可变类。
If you are creating a mutable class m, you should be prepared to write a lot more documentation about the treatment of references to m than if m were immutable.
如果您要创建一个可变类m,那么您应该准备编写比m是不可变的情况下多得多的文档说明,以说明怎样处理m的引用。
The instances of this class are immutable.
该类的实例是不可变的。
Like its global cousin, a class constant is immutable once defined.
与全局属性一样,类常量一旦定义就不可更改。
If the String class is immutable, you should never see any output from this program.
如果string类是不变的,则从此程序应当看不到任何输出。
Because the String class is immutable, and highly specified and controlled, it was practical to bring it into the fold of switch - but it was prudent to stop there.
因为string类是不变的,并且是高度具体化和受控的,所以将它放入switch中很实用,但最好不要止步于此。
Simply put, Python provides an elegant solution by including an immutable collection-based class designed to deal exclusively with sequences of characters.
简单来说,Python通过包括一个不变的基于集合的类来提供一个优秀的解决方案,这个基于集合的类是专门为有效地处理字符序列而设计的。
Building the public-immutable-field version of the Address class in Groovy yields a nice clean implementation, shown in Listing 6.
可以使用Groovy来构建公共的不可变域版本的address类,这带来的是一种非常清晰的实现,如清单6所示。
To implement mutator methods, the new LinkedList class serves as a container for an internal, immutable list, as shown in Listing 5.
为了执行可变的方法,新的LinkedList类作为一个内部不可变的链表的容器,如清单5 所示。
The in-memory representation of a schema is defined as the schema class, which is immutable and therefore thread-safe.
模式的内存中表示被定义为schema类,该类是恒定的,因此也是线程安全的。
The Rope class is designed to be immutable, meaning that mutator functions never modify the original Rope instance, but, rather, return a modified copy.
Rope类被设计成不可修改,这意味着mutator函数永远不会修改原来的Rope实例,而是返回一个修改后的副本。
There are some class immutable is impossible, then try to limit the mutability of them.
而总有些类显然不可能是不变类的,这时也要尽可能的限制它的可变性。
If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super. clone need to be modified.
如果一个类只包含基本字段或对不变对象的引用,那么通常不需要修改super .clone返回的对象中的字段。
You can fix the case above, where the called method modifies an object, by making the class immutable.
你可以修正以上的例子,当被调用方法修改一个对象时,让这个类成为不可变的。
If the value being assigned is an immutable value class, the method returns the object itself, instead of a copy of the class.
如果指派的值是不可变动的实值类别,则方法会传回物件本身,而不是类别的复本。
For the middle-class black, conditioned by these values from birth, the sense of meaning they provide is as immutable as the color of his skin.
对于中产阶级的黑 人,从出生起就受到这些价值观念的约束,人们提供的意义解释就像我的肤色是黑色的一样永恒不变。
For the middle-class black, conditioned by these values from birth, the sense of meaning they provide is as immutable as the color of his skin.
对于中产阶级的黑 人,从出生起就受到这些价值观念的约束,人们提供的意义解释就像我的肤色是黑色的一样永恒不变。
应用推荐