...
Wiki Markup |
---|
As detailed in the Java Language Specification \[[JLS 2005|AA. Java References#JLS 05]\], sectionSection 14.14.2, "The enhanced {{for}} statement", an enhanced {{for}} statement of the form: |
Code Block |
---|
for (ObjType obj : someIterableItem) { // ... } |
is equivalent to a standard for
loop of the form:
Code Block |
---|
for (Iterator myIterator = someIterableItem.iterator(); iterator.hasNext();) { ObjType obj = myIterator.next(); // ... } |
...
Attempts to assign to the loop variable from within the enhanced for
loop (for-each idiom) are futile and may leave the class in a fragile, inconsistent state.
Rule Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL05- J | low | unlikely | low | P3 | L3 |
...