Thank you for all your comments on my previous post.
Non-Issues
Using the ++ increment operator
The usage of the ++ increment operator was done deliberately and is not an issue. The difference between the two is the point in time when the value of the variable is returned. The postfix notation (i++) needs to save the value of i first and then increments. Using the ++i version helps even the dumbest compiler to generate the fastest possible code, while i++ needs at least a second operation. Today's compiler techniques should be good enough to detect that ++i and i++ are the same and the return value of i++ is not used in this situation. Using the prefix notation is more a matter of taste here.Using Typed Iterators
Using typed Iterators is surely a big advantage in Java 5. I'm a big fan of that style. But this not a real issue.The Issue
Many of you where correct that the modification of the list will be the issue. If you modify the code in the loop the issue could be easily spotted. It is more difficult to spot the problem if you just iterate through the list to get the values. Code Reviewers should be careful and consider whether the list is concurrently modified. Antony Reynolds provided the best answer here.Further Reading
- Java Concurrency in Practice, Brian Goetz
- Concurrent Programming in Java, 2nd Edition, Doug Lea