来自 Java 1.6 Collection Framework 文档:
不支持任何修改操作(如
add
、remove
和clear
)的集合称为 无法改变。[ ... ]另外保证 Collection 对象中的任何更改都不可见的集合称为 immutable。
第二个标准让我有点困惑。假设第一个集合是不可修改的,并且假设原始集合引用已被释放,那么第二行中引用的更改是什么?它是否指的是集合中元素(即元素的状态)的变化?
第二个问题:
For a collection to be immutable, how does one go about providing the additional guarentees specified? If the state of an element in the collection is updated by a thread, is it sufficient for immutability that those updates in the state are not visible on the thread holding the immutable collection?
对于不可变的集合,如何提供指定的附加保证?