immutable object meaning in English
不可变对象
Examples
- This complication is necessary to allow immutable objects to store references to arrays , since the java language has no way to enforce that elements of final arrays are not modified
为允许不变对象存储对数组的引用,这种复杂性是必要的,因为java语言没有办法强制不对final数组的元素进行修改。 - To compare value equality instead of reference equality can be useful because , as immutable objects , they can be considered the same as long as they have the same value
来比较值是否相等而不是比较引用是否相等可能会很有用,因为作为不可变的对象,只要它们具有相同的值,就可以将它们看作是相同的。 - The notion of immutability an object whose value cannot change once it s created is invaluable in multithreaded situations since read - only access to immutable objects doesn t have to be synchronized
由于对不变对象的访问不需要同步,所以在多线程条件下,不变的概念(一个对象的值在创建后不可更改)是无价的。 - There are a whole host of easy - to - commit and hard - to - detect programming errors that are entirely eliminated by using immutable objects , such as failure to synchronize access across threads or failing to clone an array or object before storing a reference to it
使用不变对象可以彻底消除许多容易发生但难以检测的编程错误,如无法在线程间同步访问或在存储对数组或对象的引用前无法克隆该数组或对象。 - The old jmm allowed some surprising and confusing things to happen , such as final fields appearing not to have the value that was set in the constructor thus making supposedly immutable objects not immutable and unexpected results with memory operation reordering
旧的jmm允许一些奇怪而混乱的事情发生,比如final字段看起来没有那种设置在构造函数里的值(这样使得想像上的不可变对象并不是不可变的)和内存操作重新排序的意外结果。