annotation

According to the usage and purpose of annotations, annotations can be divided into three categories, namely built-in annotations, meta-annotations and custom annotations.

    Built-in annotation: @Override , indicating that the current method definition will override the method in the superclass.

     @Deprecated , using the annotation for its element the compiler will issue a warning, because the annotation @Deprecated is deprecated code, deprecated code.

     @SuppressWarnings , turns off inappropriate compiler warnings.

 Meta annotations:

@Target

Indicates where the annotation can be used. Possible ElementType parameters are:

CONSTRUCTOR : the declaration of the constructor

FIELD : field declaration (including enum instances)

LOCAL_VARIABLE : Local variable declaration

METHOD : method declaration

PACKAGE : package declaration

PARAMETER : parameter declaration

TYPE: class, interface (including annotation types) or enum declaration

@Retention

Indicates the level at which the annotation information needs to be saved. Optional RetentionPolicy parameters include:

SOURCE : the annotation will be discarded by the compiler

CLASS : annotations are available in class files, but are discarded by the VM

RUNTIME : The VM will retain the annotation during runtime, so the information of the annotation can be read through the reflection mechanism.

@Document

Include annotations in Javadoc

@Inherited

Allow subclasses to inherit annotations from parent classes

Custom annotations:

(1) Define annotations

(2) Use annotations





Guess you like

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