Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Practice makes perfect

Experience is often your best defense against Java pitfalls

  • Print
  • Feedback

Page 4 of 9

E:\classes\com\javaworld\jpitfalls\article5>java com.javaworld.jpitfalls.article5.BadVisitor2
one
Exception in thread "main" java.util.ConcurrentModificationException
        at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:445)
        at java.util.AbstractList$Itr.next(AbstractList.java:418)
        at com.javaworld.jpitfalls.article5.BadVisitor2.main(BadVisitor2.java:15)


As the output shows, while we iterate, the class implementing the Iterator interface specifically checks for modification outside the iteration implementation class and throws an Exception. It would be nice if the Enumeration implementation class were upgraded with this same behavior.

  • Print
  • Feedback

Resources