Re: Annotation syntax in the JLS?
On Sun, 12 Apr 2009, Joshua Cranmer wrote:
Tom Anderson wrote:
@Foo({@Bar, @Baz, @Qux})
I don't know what that means, though.
The annotation @Foo containing a value which is an array of annotations,
specifically @Bar, @Baz and @Qux.
A better example (one that I've actually used):
@Options({
@Option(name="tabWidth", type=int.class, def="8"),
@Option(name="incWidth", type=int.class, def="4"),
@Option(name="lineWidth", type=int.class, def="80")
})
Ahaa, of course, thank you. I was being rather dense and failing to make
the connection to annotations which have values (despite the fact that i'd
already written one!). Your example makes excellent sense - you're not
allowed to have multiple annotations of the same type on a class, so you
make a container annotation to hold them.
The only annotations i really use are the JUnit ones and SuppressWarnings
(with only the "unchecked" and "serial" values). I don't do EJB or JPA,
for instance, where i understand they get more play, and perhaps because i
haven't seen them in action, i've never written any of my own. Hence, i'm
really quite ignorant about them.
tom
--
Coldplay is the kind of music computers will make when they get smart
enough to start making fun of humans -- Lower Marsh Tit