6.6 Annotating Annotations
Just as you can annotate classes, you can also annotate your own custom
annotations. This may seem a little silly at first blush, but if you
begin to build up a large repository of customized notations, this becomes
quite important. Just as Javadoc and comments are incredibly useful for a
programmer studying a previously
written class, meta-annotations, or
annotations on annotations, are indispensable for figuring out someone
else's intent for a customized annotation.
6.6.1 How do I do that?
There are four standard meta-annotations, all defined in the java.lang.annotation package:
Target
This meta-annotation specifies which program elements can have
annotations of the defined type.
Retention
This meta-annotation indicates whether an annotation is tossed out
by the compiler, or retained in the compiled class file. In cases where
the annotation is retained, it also specifies whether it is read by the
Java virtual machine at class load.
Documented
This meta-annotation indicates that the defined annotation should
be considered as part of the public API of the annotated program element.
Inherited
This meta-annotation is intended for use on annotation types that
are targeted at classes, indicating that the annotated type is an
inherited one.
These are all somewhat self-explanatory, so with a few examples, these
meta-annotations should be easy to put into use. Each is covered in
detail in the next several labs.