关于 ArrayList 的modCount属性,java源码里面写的注释很长一大串,不是一时半会可以看的明白的。我就做个记录,翻译一下。
翻译的也仅供看个大概吧。我就留个笔记备用吧。
/**
* The number of times this list has been <i>structurally modified</i>. 这个list的结构已经被修改过的次数
* Structural modifications are those that change the size of the 结构修改是那些改变list的size属性,
* list, or otherwise perturb it in such a fashion that iterations in 或者其他方式如迭代进度可能会产生不正确的结果
* progress may yield incorrect results.
*
* <p>This field is used by the iterator and list iterator implementation 这个字段是由迭代器和列表迭代器实现的
* returned by the {@code iterator} and {@code listIterator} methods. 代码迭代器listIterator方法返回的代码
* If the value of this field changes unexpectedly, the iterator (or list 如果此字段的值意外更改,则迭代器(list迭代器)
* iterator) will throw a {@code ConcurrentModificationException} in 将在响应迭代器的next方法,remove方法,previous(),set(),add()等方法
* response to the {@code next}, {@code remove}, {@code previous}, 抛出concurrentmodificationexception 异常
* {@code set} or {@code add} operations. This provides 这提供了
* <i>fail-fast</i> behavior, rather than non-deterministic behavior in 快速失败的行为,而不是在面对迭代过程中,并发修改的非确定性行为
* the face of concurrent modification during iteration.
*
* <p><b>Use of this field by subclasses is optional.</b> If a subclass 子类们使用这个字段是可选的,如果一个子类
* wishes to provide fail-fast iterators (and list iterators), then it 希望提供快速失败的迭代器(lsit迭代器),那么 它
* merely has to increment this field in its {@code add(int, E)} and 仅仅需要增加这个字段在他的 add,remove,方法
* {@code remove(int)} methods (and any other methods that it overrides (或者其他任何修改了list结构的方法)
* that result in structural modifications to the list). A single call to 一个单一的调用
* {@code add(int, E)} or {@code remove(int)} must add no more than add()或者remove()方法,必须增加不超过
* one to this field, or the iterators (and list iterators) will throw 1 的大小的值,给这个字段。否则,迭代器或者list迭代器将抛出
* bogus {@code ConcurrentModificationExceptions}. If an implementation ConcurrentModificationExceptions 异常 如果一个实现
* does not wish to provide fail-fast iterators, this field may be 不希望提供快速失败迭代器,这个字段可以忽视
* ignored.
*/