package java.lang.annotation;
@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.ANNOTATION_TYPE)public@interface Target {
/**
* Returns an array of the kinds of elements an annotation type can be applied to.
* @return an array of the kinds of elements an annotation type can be applied to
*/
ElementType[] value();
}
publicenumElementType{
/** Class, interface (including annotation type), or enum declaration */
TYPE,
/** Field declaration (includes enum constants) */
FIELD,
/** Method declaration */
METHOD,
/** Formal parameter declaration */
PARAMETER,
/** Constructor declaration */
CONSTRUCTOR,
/** Local variable declaration */
LOCAL_VARIABLE,
/** Annotation type declaration */
ANNOTATION_TYPE,
/** Package declaration */
PACKAGE,
/** Type parameter declaration */
TYPE_PARAMETER,
/** Use of a type */
TYPE_USE
}
再看@Target
package java.lang.annotation;
@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.ANNOTATION_TYPE)public@interface Target {
/**
* Returns an array of the kinds of elements an annotation type can be applied to.
* @return an array of the kinds of elements an annotation type can be applied to
*/
ElementType[] value();
}
package java.lang.annotation;
@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.ANNOTATION_TYPE)public@interface Retention {
/**
* Returns the retention policy.
* @return the retention policy
*/RetentionPolicy value();
}
RetentionPolicy
publicenumRetentionPolicy{
/**
* Annotations are to be discarded by the compiler.
*/
SOURCE,
/**
* Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior.
*/
CLASS,
/**
* Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.
*/
RUNTIME
}