Java Annotations List

Source: Internet
Author: User

@Target (TargetType)

Used to indicate that the type can be applied annotation.

If a annotation does not define a target, then the annotation can appear on any element.

The parameter of target is the java.lang.annotation.elementtype.* type:

    • ANNOTATION_TYPE:annotation
    • CONSTRUCTOR:构造方法
    • Field: Class field, including enum
    • local_variable: Local Variables
    • Method: Methods
    • Package: Packages
    • PARAMETER: Parameters
    • TYPE:类、接口、annotation、enum

Such as:

This metaannotationtype can only appear when defining annotation
@Target (elementtype.annotation_type)
public @Interface metaannotationtype { ...}
@Retention (Tetention-policy)

Retention defines annotation failure timing.

The value is the java.lang.annotation.retentionpolicy.* type, the specific value:

    • Source: Only takes effect in the source phase, such as @override, @SuppressWarnings
    • Class (default): Invalid when class is loaded, but valid when compiled into a binary file
    • Runtime: Will not expire. such as: @Deprecated
Importjava.lang.annotation.Retention;ImportJava.lang.annotation.RetentionPolicy;//This type of annotation does not expire@Retention (retentionpolicy.runtime) @Interfacemyannotation {String stringvalue (); intintvalue ();} Public classMainClass {//at run time, you can get the information of Myannotation@MyAnnotation (stringvalue = "Annotation Example", intvalue = 100)   Public Static voidMyMethod () {}}

@Documented

The Java element used to indicate the configuration of this annotation is Javadoc documented.

@Documented @inherited   // For descenders of the annotation to the @documented feature automatically // must be there  public @Interface  inwork {    ... /** * Annotated class   */  = "")publicclass  Mainapp {    ...

If you use Javadoc to get the doc document, you will see the Mainapp document

@Configuration

Used to indicate that class can be used by the spring IOC container as a bean definition

Java Annotations List

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.