Java annotations are some of the meta-information that is attached to the code, used by some tools to parse and use at compile and run time, to illustrate and configure functionality.
Annotations do not and do not affect the actual logic of the code, only the ancillary role. Included in the Java.lang.annotation package.
1, Yuan annotation
Meta annotations are annotations of annotations. including @Retention @Target @Document @Inherited four kinds.
1.1. @Retention: Define retention policies for annotations
@Retention (Retentionpolicy.source)//annotations only exist in the source code and are not included in the class bytecode file@Retention (Retentionpolicy.class)//default retention policy, annotations exist in the class bytecode file, but are not available at run time .@Retention (Retentionpolicy.runtime)//annotations are present in the class bytecode file and can be obtained through reflection at run time1.2. @Target: Define the purpose of the annotation the source code for its definition is:@Documented@Retention (retentionpolicy.runtime)@Target (Elementtype.annotation_type)public @interface Target {
- Elementtype[] Value ();
}
@Target (Elementtype.type)//interfaces, classes, enumerations, annotations@Target (Elementtype.field)//fields, constants for enumerations@Target (Elementtype.method)//Method@Target (Elementtype.parameter)//Method parameters@Target (Elementtype.constructor)//Constructors@Target (elementtype.local_variable)//Local variables@Target (Elementtype.annotation_type)//Annotations@Target (Elementtype.package)/// packageBy the above source code can know, his elementtype can have multiple, an annotation can be class, method, field and so on 1.3, @Document: Explain that the note will be included in Javadoc 1.4, @ Inherited: The description subclass can inherit this annotation from the parent class
For specific examples, refer to: http://blog.csdn.net/yixiaogang109/article/details/7328466
Java Custom Annotations