Common annotations in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.