I think the identifier of a foreach should get an AssignmentConversion. The JLS says that “meaning of the enhanced for statement is given by translation into a basic for statement” (http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2). But if they bothered to specify it properly I’m sure they’d have mentioned it ;)

Without this the type-checker can’t tell this is wrong:
for(double d : new java.util.ArrayList()) { … }

Submitted on 4 April 2007 at 18:59

Log in to post comments