Meta-annotations in Java annotations

  The four meta-annotations in Java annotations are: @Target, @Retention, @Documented, @Inherited.
  Meta-annotations are provided by the java API and are specially used to define annotations. Their functions are as follows:
      (1) @Target indicates where the annotation is used. The possible values ​​are in the enumeration class ElemenetType, including:
          ElemenetType.CONSTRUCTOR ---------------------------- Constructor declaration
          ElemenetType.FIELD ---------------- ---------------------- Domain declarations (including enum instances)
          ElemenetType.LOCAL_VARIABLE----------------- ------- Local variable declaration
          ElemenetType.METHOD ---------------------------------- Method declaration
          ElemenetType .PACKAGE --------------------------------- Package declaration
          ElemenetType.PARAMETER ---------- --------------------Parameter declaration
          ElemenetType.TYPE------------------------- -------------- class, interface (including annotation types) or enum declaration           
     (2) @Retention indicates at what level the annotation information is saved. Optional parameter values ​​are in the enumeration type RetentionPolicy, including:
          RetentionPolicy.SOURCE --------------------------------- Annotations will be discarded by the compiler
          RetentionPolicy.CLASS ----------------------------------- Annotations are available in class files , but will be discarded by the VM
          RetentionPolicy.RUNTIME-------JVM will also retain annotations during runtime, so the annotation information can be read through the reflection mechanism.
     (3) @Documented includes this annotation in javadoc, which means that this annotation will be extracted into a document by the javadoc tool.

  The content in the doc document will vary depending on the information content of this annotation. Equivalent to @see, @param etc.      
    (4) @Inherited allows subclasses to inherit annotations from the parent class.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325075777&siteId=291194637