Community
Participate
Working Groups
According to Sun, the following annotation is illegal, per http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6294589 ------------------ Bug.java -------------- public class Bug { { for ( @SuppressWarnings("unusedLocal") Byte i : new Byte[]{} ) ; } }
Interesting. Looking at the Language Specification, I can't find anything that would not allow this.
Local variables can be associated modifiers, and thus are eligible for annotations.
Grammar spec says: EnhancedForStatement: for ( VariableModifiersopt Type Identifier: Expression) Statement VariableModifiers: VariableModifier VariableModifiers VariableModifier VariableModifier: one of final Annotation
An annotation placed on a local variable is not persisted in the .class file, but it is perfectly fine in the source.