Java Reference
In-Depth Information
You can specify multiple element types when applying the
Target
an-
notation. For example, an annotation type that only applies to fields or
local variables would be annotated with
@Target({ ElementType.FIELD, ElementType.LOCAL_VARIABLE })
Our
Revision
annotation type could also be annotated with:
@Target(ElementType.TYPE)
to restrict its applicability to type declarations. If an annotation type has
no
@Target
meta-annotation then it is applicable anywhere.
Don't confuse the applicability of an annotation type with the access-
ibility of the annotation type. If an annotation is public then it can be
used anywhere, but its applicability might restrict what elements it can
be applied to. Conversely, you can't apply an annotation if it is inac-
cessible, even if you are trying to apply it to the right kind of element.
Restricting the applicability of an annotation does not affect its use with-
in other annotation types. For example, if
Revision
were restricted to use
on local variables (not that it makes sense), that doesn't stop
ClassInfo
from having an element of type
Revision
.