In-depth understanding of Java: Annotations (Annotation) Getting Started with custom annotations----http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html
In-depth understanding of Java: Annotations (Annotation)--Annotation Processor-----http://www.cnblogs.com/peida/archive/2013/04/26/3038503.html
One of the first articles mentions:
There are four meta annotations:
For the JDK's explanation:
Documented
: Indicates that a comment of a type will be documented through Javadoc and similar default tools.
Inherited
: Indicates that the annotation type is automatically inherited.
Retention
: Indicates how long comments for the annotation type are to be retained.
Target
: Indicates the kind of program element that the annotation type applies to.
Target
and retention respectively have ElementType Retentionpolicy to set.
Public enum Retentionpolicy { SOURCE, CLASS, RUNTIME;}
Public enum ElementType { TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, local_variable, Annotation_type, package;}
So you need to look at the meanings of the ElementType and Retentionpolicy enum types:
ElementType:
annotation_type Annotation Type declaration
CONSTRUCTOR constructor Method declaration
Field field declaration (including enumeration constants)
local_variable local variable declaration
Method declaration
Package Declaration
PARAMETER parameter declaration
Type class, interface (including annotation type), or enumeration declaration
Retentionpolicy constants of this enumeration type describe the different strategies for preserving annotations.
The class compiler will record annotations in the class file, but the VM does not need to keep annotations at run time.
The runtime compiler records annotations in the class file, and the VM retains comments at run time, so it can be read in a reflective manner.
The comment that the SOURCE compiler will discard.
But there is a problem:
Look at a document that says a specific annotation @tx ("template") can only be used in the main method, if the inheritance is not effective, you need to see why this is.
Java Annotations Annotation Learning---two good blogs