Java annotation
Annotation is actually a special tag in the code. These tags can be obtained during compilation, class loading and runtime, and the corresponding processing can be performed. By using annotations, programmers can embed some supplementary information in the source file without changing the original logic.
Annotations can be used like modifiers to modify the declarations of packages, classes, constructors, methods, member variables, parameters, and local variables. This information is saved in the name = value of the annotation.
Annotations can be used to set metadata for program elements (classes, methods, member variables, etc.).
When using annotation, an @ symbol should be added before it, and the annotation should be used as a modifier to decorate the program elements it supports.
Three basic annotations:
Custom annotation:
Define a new annotation type and use the @ interface keyword;
The annotation member variable is declared in the annotation definition in the form of no parameters, and its method name and return value define the name and type of the member;
You can specify an initial value for an annotated member variable when it is defined. You can use the default keyword to specify the initial value of a member variable;
Annotations without member definitions are called tags, and annotations containing member variables are called metadata annotations;