Wednesday, April 27, 2011

Target annotation in java

Target indicates which program element(s) can be annotated using instances of the annotated annotation type. The value of Target is one of the members of the java.lang.annotation.
ElementType enum:
  1. ANNOTATION_TYPE. The annotated annotation type can be used to annotate
    annotation type declaration.
  2. CONSTRUCTOR. The annotated annotation type can be used to annotate
    constructor declaration.
  3. FIELD. The annotated annotation type can be used to annotate field declaration.
  4. LOCAL_VARIABLE. The annotated annotation type can be used to annotate local
    variable declaration.
  5. METHOD. The annotated annotation type can be used to annotate method declaration.
  6. PACKAGE. The annotated annotation type can be used to annotate package declarations.
  7. PARAMETER. The annotated annotation type can be used to annotate parameter declarations.
  8. TYPE. The annotated annotation type can be used to annotate type declarations.
@Target(value=METHOD)
You can have multiple values in the Target annotation.


@Target(value={TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR,
LOCAL_VARIABLE})

No comments:

Post a Comment

Chitika