[JSR308] annotations on types of the local variables
eu at javatx.org
Fri May 18 20:58:23 EDT 2007
David Wagner wrote:
>> Several members of the Java compiler team suggested that it is a bad
>> idea to use @Target meta-annotation to guard against ambiguity of those
>> annotations. I guess the primary concern is that grammar scanner can't
>> tell what type of annotation it is and it will also require an extra
>> steps in the AST processor. So, we should at least include this into the
>> list of unresolved issues.
> I would like to argue that this objection should be given a very low
> priority. Syntax should be designed to make it easy for programmers to
> understand and use, and a minor impact on compiler writers seems like
> it should be distinctly secondary.
> If the JSR's syntax is considered the best for programmers, and if that
> means that an extra step in the AST processor is required, so be it.
> I'd much rather see the compiler writer have to do a little extra work
> than force programmers to use an inferior syntax.
David, I would agree with you that is not too severe issue from the
practical point of view.
However, from the language design point of view, the argument I've
heard is that programmer (or scanner) can't tell annotation type just
looking at the source code where annotation is used. So, the annotation
meaning is ambiguous within that code and ambiguity is resolved using
meta-annotation that developer (and compiler) need to look at (either
going into the annotation sources or using help from the IDEs).
Also note that @Target annotation is optional, so it may lead to the
unexpected side effects, when developer meant to put type annotation but
got annotation for the local variable instead. This probably won't have
much impact on the Java source or AST level, but those annotations may
have different representation in the bytecode.
Anyways, the reason I brought it up is to make sure we settle on this
issue and get into an agreement at least within the expert group. So, it
would also help to decide which annotation syntax works best.
More information about the JSR308