返回信息流private abstract class HashIterator<E> implements Iterator<E> {
Entry<K,V> next; // next entry to return
int expectedModCount; // For fast-fail
int index; // current slot
Entry<K,V> current; // current entry
HashIterator() {
expectedModCount = modCount;
if (size > 0) { // advance to first entry
Entry[] t = table;
while (index < t.length && (next = t[index++]) == null)
;
}
}
对其中的构造方法while循环,不太理解其含义还请高手分析一下。
这是一条镜像帖。来源:北邮人论坛 / java / #36705同步于 2014/11/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
关于HashMap中HashIterator中的代码求帮分析??
iambest
2014/11/30镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
【 在 skygo 的大作中提到: 】
: 是它指向的所有节点都不能为空
它在Iterator获取下一个Entry时,进行了判断,感觉构造方法里不用使用while循环了,其实它就是什么也没做吧
final Entry<K,V> nextEntry() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
Entry<K,V> e = next;
if (e == null)
throw new NoSuchElementException();
if ((next = e.next) == null) {
Entry[] t = table;
while (index < t.length && (next = t[index++]) == null)
;
}
current = e;
return e;
}