private class Itr implements Iterator<E> {
public void remove() {
if (lastRet == -1)
throw new IllegalStateException();
checkForComodification();
try {
AbstractList.this.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
//expectedModCount保持和modCount一致
expectedModCount = modCount;
} catch (IndexOutOfBoundsException e) {
throw new ConcurrentModificationException();
}
}
}
Itr是AbstractList的内部类,通过类名.this即可得到外部类的对象引用;
外部内OutClass,内部类InnerClass,创建内部类InnerClass对象:
OutClass out = new OutClass();
OutClass.InnerClass inner = out.new InnerClass();