JDK 5 provides annotations, in addition to retention, there are another three, namely target, inherited and documented.
Target target, where the target annotation is used, defines the timing of the annotation, that is, the type of program element to which the annotation applies. If the Target meta annotation does not exist in the annotation type declaration, the declared type can be used on any program element. If such a meta annotation exists, the compiler enforces the specified usage limit.
Target is defined as follows:
@Documented
@Retention (retentionpolicy.runtime)
@Target (elementtype.annotation_type) public
@ Interface Target {
elementtype[] value ();
}
As you can see, Target has only one value property, and the type is enumerated type ElementType. The ElementType statement reads as follows:
public enum ElementType {
/** annotations can be used in classes, interfaces (including annotation types) or enum declaration/type
,
/** field declarations (including enumeration constants)/Field
,
/** METHOD declaration * *
,
/** parameter declaration/
PARAMETER,
/** Construction Method declaration * * *
constructor,
/** local variable declaration
/ local_variable,
/** Annotation type declaration * * *
Annotation_type,
/** Package declaration/
PACKAGE
}
The documented annotation indicates whether the annotation information is added to the document when making Javadoc. If the annotation uses @documented when it is declared, the annotation information is added to Javadoc when you make Javadoc. The annotation statement is as follows:
@Documented
@Retention (value=runtime)
@Target (value=annotation_type) to indicate that the annotation can only be used when declaring annotations, that is, the meta annotation public
@ Interface documented {}
The inherited annotation is also a meta annotation and is declared as follows:
@Documented
@Retention (value=runtime)
@Target (value=annotation_type) public
@interface inherited {}
The inherited annotation indicates whether the annotation inherits from the quilt class, and the default is not inherited. When the annotation is declared, the @inherited annotation is used, and the annotation is inherited by subclasses of the class that used the annotation.