20 lines
505 B
Java
20 lines
505 B
Java
|
//: containersindepth/FailFast.java
|
|||
|
// <20>2015 MindView LLC: see Copyright.txt
|
|||
|
// Demonstrates the "fail-fast" behavior.
|
|||
|
import java.util.*;
|
|||
|
|
|||
|
public class FailFast {
|
|||
|
public static void main(String[] args) {
|
|||
|
Collection<String> c = new ArrayList<>();
|
|||
|
Iterator<String> it = c.iterator();
|
|||
|
c.add("An object");
|
|||
|
try {
|
|||
|
String s = it.next();
|
|||
|
} catch(ConcurrentModificationException e) {
|
|||
|
System.out.println(e);
|
|||
|
}
|
|||
|
}
|
|||
|
} /* Output:
|
|||
|
java.util.ConcurrentModificationException
|
|||
|
*///:~
|