20 lines
498 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: containers/FailFast.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
// Demonstrates the "fail-fast" behavior.
import java.util.*;
public class FailFast {
public static void main(String[] args) {
2015-05-05 11:20:13 -07:00
Collection<String> c = new ArrayList<>();
2015-04-20 15:36:01 -07:00
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
*///:~