Just wondering what annotations could be used with variables declared in try-with-resources statements, which is allowed as per its grammar. The section 14.20.3 from the language specification (Java 7) reads,
TryWithResourcesStatement:
tryResourceSpecification Block Catchesopt FinallyoptResourceSpecification:
(Resources;opt)Resources:
Resource Resource;ResourcesResource:
VariableModifiersopt Type VariableDeclaratorId=Expression
And VariableModifiers expands as (section 14.4),
VariableModifiers:
VariableModifier
VariableModifiers VariableModifierVariableModifier: one of
Annotationfinal
There you go: VariableModifier can have Annotation. Well, that basically means, we can write something like this:
try( @SomeAnnotation SomeType obj = createSomeType() ) {
//some code
}
So my question is: how and what kind of annotations could possibly be used in try-with-resources and to achieve what kind of behaviors? Any innovative idea? Have anybody used them?