Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider what fail-fast iterator behaviour promises. Which statement is correct?

  • A.It guarantees the modification is rolled back so the iterator stays valid.
  • B.It usually throws ConcurrentModificationException, on a best-effort basis only.
  • C.It always throws ConcurrentModificationException at the moment of the modification.
  • D.It guarantees the iteration continues safely over a snapshot of the collection.

Answer: B

The javadoc is careful here: the behaviour cannot be guaranteed in the presence of unsynchronized concurrent modification, so it throws on a best-effort basis and a program must not depend on the exception for correctness. It is a way of catching bugs, not a safety mechanism.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.