Skip to content

fix: 修正增强 for 循环中 Iterator fail-fast 机制的描述#2820

Merged
Snailclimb merged 1 commit intomainfrom
fix/syntactic-sugar-iterator-description
Apr 9, 2026
Merged

fix: 修正增强 for 循环中 Iterator fail-fast 机制的描述#2820
Snailclimb merged 1 commit intomainfrom
fix/syntactic-sugar-iterator-description

Conversation

@Snailclimb
Copy link
Copy Markdown
Owner

Summary

  • 修正增强 for 循环坑点中关于 ConcurrentModificationException 原因的错误描述
  • 原文错误地声称 Iterator 工作在独立线程中并持有 mutex 锁,实际机制是通过 modCount / expectedModCount 计数器比较实现 fail-fast
  • 同时修正 Iterator.remove() 的说明:原文说"维护索引的一致性",实际是同步更新 expectedModCount

Closes #2818

Test plan

  • 确认修改后的描述与 JDK 源码(如 ArrayList.Itr)中 fail-fast 实现一致

原描述错误地声称 Iterator 工作在独立线程中并持有 mutex 锁,
实际机制是通过 modCount/expectedModCount 计数器比较实现 fail-fast。
同时修正了 Iterator.remove() 的说明。

Closes #2818
@Snailclimb Snailclimb merged commit d30088b into main Apr 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 语法糖详解中的可能遇到的坑部分的增强for循环的问题

1 participant