Common annotations in Java
1, the JDK comes with annotations @override @Deprecated @Suppvisewarnings
Common third-party annotations
Spring: @Autowired @Service @Repository
Mybatis: @InsertProvider @UpdateProvider @Options
Classification of annotations:
In accordance with the mechanism of implementation:
Source code annotations: Annotations only exist in the source code, compiled into a. class file will not exist;
Compile-time annotations: Annotations are present in both the source code and the. class file (the three annotations (@Override @Deprecated @Suppvisewarnings) from the JDK are compile-time annotations and only work at compile time)
Annotation at execution time: It also works in the execution phase. Annotations that can even affect execution logic (@Autowired)
According to the source points:
Annotations from the JDK's own
Third-party annotations
Our own definition of annotations
SOURCE annotations: Annotations for callouts
Package Com.ann. define annotations yourself; Import Java.lang.annotation.documented;import Java.lang.annotation.elementtype;import Java.lang.annotation.inherited;import Java.lang.annotation.retention;import Java.lang.annotation.RetentionPolicy Import Java.lang.annotation.Target; @Target ({elementtype.method,elementtype.type})//Annotation Scope: Method, class Interface @retention ( Retentionpolicy.runtime)//Annotation life cycle: Source class runtime@inherited//(original annotation of identity) consent to subclass inheritance @documented//generate Javadoc will include annotations// Define annotations using @integrfacekeyword, which means that the definition is not a class or interface public @interface Description {//Members are declared with no exception (no exceptions)//member types are restricted, valid types include primitive types and string Class Annotation enumeration//Most of the annotations that are defined by the original type and string are sufficient//assuming that the annotation has only one member, the member name must be named value () and the member name and assignment number (=) can be ignored when used. The annotation class can have no members. Annotations without members are called identity annotations, string desc (); String author (); int age () default 18;//ability to set a defaults for a member
Common annotations in Java