20 lines
459 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// containersindepth/FailFast.java
2015-06-15 17:47:35 -07:00
// 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);
}
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
java.util.ConcurrentModificationException
2015-09-07 11:44:36 -06:00
*/