In the previous article, we explained: the definition of annotations in Java, JDK built-in notes, third-party comments.
This article is the second in series of tutorials comment. Take a look at the main contents of today:
0e5bfb282785e6d50be398c29a4d9267.png
1: Classification annotated
2: a meta-annotation Description
3: custom annotation statement
I: Classification annotations
c03d16d65e241c90e669f077a650bb64.png
NOTES Depending on the operating mechanism, origin, function points:
1.1: In accordance with the operating mechanism of points, there is immediate comment on what stage of the program
e0c7d7da2e69a56219d73cd8be1c4454.png
Source notes (source): present in the source code.
Such as: lombak of @data notes:
5bea68c9466087e5e29d6a07d6243893.png
Compile notes (class): compile time. Both are in the source code and class.
JDK comes with three notes (@Override (rewrite covers), @ Deprecated (obsolete, outdated), @ Suppvisewarnings (compression warning)) is a compilation of comments
For example: override
0362f1164684a55d250ef62a5774a78a.png
Run a comment (runtime): In the operational phase of any course work, and even affect the operation logic.
Such as: spring of autowired notes:
f39084e8c5e64a0834714f102eca9160.png1.2: According to the source to distinguish both notes come from
According to the source to differentiate into: JDK comes with notes, annotations third-party, custom annotations
As shown below:
e53b73770958773c2e330afeeb8c1007.png
1.3: according to the function to distinguish between:
According to the function to distinguish, can be divided into: a meta-annotation and non-yuan notes. As shown below:
afafe3546c589b9575096a6827d8b692.png
II: Yuan notes explain
2.1: What is a meta-annotation?
Meta-annotation refers to the annotated notes. JAVA Ghost Notes includes the following four:
7ac1431ceef05b2463a25ba3da4a9cd7.png
2.2:@Target
target annotation functions: labeling annotation scope. If there are multiple scopes divided by commas
target annotation scope What?
Constructors, fields, local variables, methods, kits, parameters, interfaces. FIG follows:
f04c44ad40c7473701ac705c2bbfd82d.png
e6e365e0dbc15a00bebd6df6df9def1a.png
2.3:@Retention
The role of retention: the life cycle of annotations.
Notes life cycle, what does?
souce only in the source display, compile the class, the existence of run time runtime. As shown below:
b19e1e745582b64fb7031b7e68f3e3c3.png
Lifecycle Size:
4dc0e0c220fc15304fe3ab2bb5460028.png
2.4:@Inherited
inherite: identification of yuan notes. Identify the current annotation can be inherited by child comment
de34f5ca04abc46443777f3f189cce47.png
2.5:@Documented
documented: at the time of document generation, will be included
cbb4bfcc5975de05f4f84e3ebd1f28b6.png
Three: custom annotation wording:
@Target({ElementType.METHOD, ElementType.FIELD})br/>@Retention(RetentionPolicy.RUNTIME)
@Inheritedbr/>@Documented()
public @interface MyAnnotation1 {
public abstract String value();
}
9c58e2d4fa3ef4e29cf4a65c78ab272d.png
Disclaimer: This article is distributed by Kaige (Kaige Java) Java Annotations The second series of tutorials to learn. Without permission, shall not be reproduced
This article Source: http://www.kaigejava.com/article/detail/440
Kaige blog: www.kaigejava.com
Kaige public number: Kaige Java (kaigejava)