Meta ‘Target’ Annotation

Meta Annotation which is also called as Annotation of Annotation. This is of four types:

  1. Target
  2. Retention
  3. Documented
  4. Inherited

The Target Annotation

The target annotation indicates the targeted elements of a class in which the annotation type will be applicable. It contains the following enumerated types as its value:

  • @Target(ElementType.TYPE)—can be applied to any element of a class
  • @Target(ElementType.FIELD)—can be applied to a field or property
  • @Target(ElementType.METHOD)—can be applied to a method level annotation
  • @Target(ElementType.LOCAL_VARIABLE)—can be applied to local variables
  • @Target(ElementType.PARAMETER)—can be applied to the parameters of a method
  • @Target(ElementType.CONSTRUCTOR)—can be applied to constructors
  • @Target(ElementType.ANNOTATION_TYPE)—indicates that the declared type itself is an annotation type





The @Target(ElementType.METHOD) indicates that this annotation type can be used to annotate only at the method levels.



Above code will work fine. Because annotation type was for method level. 



Above code will not work fine. Because annotation type was for method level and string variable has been added between target annotation and method. 







  1. Annotations and Its Benefits in Java
  2. Advantages Of Annotations Over XML
  3. Annotation Programming Basics
  4. Annotation Types
    1. Simple Annotation
    2. Meta Annotation
      1. Meta ‘Target’ Annotation
      2. Meta ‘Retention’ Annotation
      3. Meta ‘Documented’ Annotation
      4. Meta ‘Inherited’ Annotation
  5. Reflection to Extract Annotation Details

Leave a Reply

Your email address will not be published. Required fields are marked *