友好服饰

文章
6
资源
0
加入时间
3年1月8天

HashMap 中的 fail-fast(快速失败机制)

当 HashMap 在迭代过程中,结构发生变化时,会抛出 ConcurrentModificationException 错误,称为快速失败机制。​ 对 HashMap 进行迭代:Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator();​ Q:HashMap 是如何实现 fail-fast 机制的?1. HashMap 会维护一个 modCount