我一直在读Java泛型和集合这本书,在讨论迭代器的一节中,作者提到了
Collections which rely on CAS (compare and swap) have weakly consistent iterators, which reflect some but not necessarily all of the changes that have been made to their backing collection since they were created. For example, if elements in the collection have been modified or removed before the iterator reaches them, it definitely will reflect these changes, but no such guarantee is made for insertions. Weakly consistent iterators also do not throw ConcurrentModificationException.
我想知道,为什么弱一致迭代器只反射(reflect)修改和删除的变化,而不反射(reflect)插入的变化。定义这样的行为背后的原因是什么?它有什么用途?
请您参考如下方法:
我认为这是不正确的。 official definition 弱一致迭代是:
- they may proceed concurrently with other operations
- they will never throw
ConcurrentModificationException- they are guaranteed to traverse elements as they existed upon construction exactly once, and may (but are not guaranteed to) reflect any modifications subsequent to construction.
删除和插入之间没有区别。
