Search |
||
@nnotation type or type @nnotationPosted by forax on March 18, 2007 at 7:42 AM PDT
The purpose of JSR 308 is to allow to
define annotation on types.
Why allowing this is a good idea ? There is real interest to allow annotation on Java types, it enables to write safer code by performing static source code analysis. Imagine annotations like:
There are two possible syntax, the first one is to allow annotation of type at the left of the type like any other Java annotations. But it introduce an ambiguity because a reader doesn't see clearly if an annotation belong to a variable, a method etc. or its type. In the following sample, @NonNull refers to String and @Column refers to name.
@Local
class MyBean {
@NonNull @Column(name="_NAME") String name;
@Deprecated @NonNull Dimension getSize() { ... }
}
The second one is to allow annotation on type at the right of a type, in that case there is no ambiguity.
@Local
class MyBean {
@Column(name="_NAME") String @NonNull name;
@Deprecated Dimension @NonNull getSize() { ... }
}
The JSR308 expert group seems to think that the first syntax is
better, more Java-like even if it introduce an ambiguity.
What do you think ? Cheers, Rémi »
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|