Skip to content

Tag: annotations

How @Target(ElementType.ANNOTATION_TYPE) works

Java annotations are marked with a @Target annotation to declare possible joinpoints which can be decorated by that annotation. Values TYPE, FIELD, METHOD, etc. of the ElementType enum are clear and simply understandable. Question WHY to use @Target(ANNOTATION_TYPE) value? What are the annotated annotations g…

Passing annotation properties to meta-annotations

Say I have an annotation with a property: and I want to create a compound annotation with several meta-annotations, including the one that takes a property Is there a way that I can pass properties to the compound annotation to one of the meta annotations? Eg, something like this: that is equivalent to, but m…

Default properties of Java Annotation

What are the exact default values of two meta annotations (Target and Retention) in a user defined annotation? Answer According to the source code, none of them has a default value, which means you must provide it, whenever you use the annotation. The meaning of the missing annotation is defined in the javado…