java.lang.annotation.ElementType
:
A program element type. The constants of this enumerated type provide a simple classification of the declared elements in a Java program. These constants are used with the Target
meta-annotation type to specify where it is legal to use an annotation type.
There are the following constants:
Can someone explain what each of them are (where they'd be annotated in actual code)?
This summarizes the main ones:
@CustomTypeAnnotation
public class MyAnnotatedClass {
@CustomFieldAnnotation
private String foo;
@CustomConstructorAnnotation
public MyAnnotatedClass() {
}
@CustomMethodAnnotation
public String bar(@CustomParameterAnnotation String str) {
@CustomLocalVariableAnnotation String asdf = "asdf";
return asdf + str;
}
}
ANNOTATION_TYPE is an annotation on another annotation, like this:
@CustomAnnotationTypeAnnotation
public @interface SomeAnnotation {
..
}
Package is defined in a package-info.java
file in the package, like this:
@CustomPackageLevelAnnotation
package com.some.package;
import com.some.package.annotation.PackageLevelAnnotation;