meta-annotations [email protected] @inherited @Retention @Documented
@Retention: This annotation is noted on other annotations and is used to describe how to store annotations that have been marked. Information that is used to mark annotations and provide annotations. The possible values are:
- Source: Indicates that this annotation will be ignored by the compiler and will only remain in the source code.
- Class: Indicates that this annotation will reside in the class file by compiling, but will be ignored by the JVM at run time, and because of this, it is not visible at run time.
- Runtime: Indicates that this annotation is fetched by the JVM and is obtained through reflection at run time.
@Target: This annotation is used to limit the types that an element can be annotated with. For example:
Annotation_type--------------indicates that the annotation can be applied to other annotations
CONSTRUCTOR-------------------indicates that a field can be used on the constructor to indicate that it can be used on a field or property
The local_variable-----------------indicates that it can be used on local variables.
Method---------------------------can be used at the annotation level.
The package--------------------------can be used on the packet declaration.
PARAMETER-----------------------can be used on the parameters of the method
Type-------------------------------can be used on any element of a class
@Documented: The annotated element will be used as the content in the document produced by the Javadoc. Annotations do not become content in the document by default. This annotation can be used for other annotations.
@Inherited: Annotations do not inherit from the quilt class by default. Annotations marked with this annotation are inherited by all subclasses. This annotation can be used on classes.
Some frequently used annotations:
- @Override: Explains to the compiler that the annotated element is an element of the overridden parent class. This annotation is not mandatory when overriding the parent class element, but can help the compiler generate an error when overriding the error to remind us. For example, the parameters of a subclass method do not match the parent class, or the return value type is different.
- @Repeatable: Annotations that illustrate the annotation's identity can be used more than once to the declaration of the same element.
- @Test: This annotation illustrates to junit that the annotated method must be an executable test method. This annotation can only be identified on the method and is persisted to the runtime by the JVM.
- @Before: This annotation is used to illustrate to junit that the method being tagged should be executed before all test methods. This is useful for setting up the test environment and initialization before testing. The same applies only to methods:
- @After: This annotation is used to illustrate to junit that the annotated method should be performed after all unit tests. This annotation is often used to destroy resources, close, release resources, or clean, reset, and so on.
- @Ignore: This method is used to illustrate to junit that the annotated method should not be performed as a test unit. Even if it is annotated as a test method, it can only be ignored.
- @Component: Describes the tagged element, which in this case is a class, is a target for automatic detection. This means that the annotated class will be instantiated and managed by the spring container.
- @Autowired: The spring container will attempt to assemble automatically using this set method through the type (which is an element-matching mechanism). This annotation can also be used on constructors and attributes, and spring also takes different actions depending on where the annotations are.
- @FixMethodOrder: Specifies the order of execution, in which case the JUnit handler is responsible for executing it in a completely random, unpredictable order. This annotation is not recommended when all test methods are independent of each other. However, this annotation comes in handy when the test scenario requires a test method that follows certain rules.
-
@Deprecated: Indicates that the tagged element should not be used again. This annotation causes the compiler to generate a warning message. Can be used on methods, classes, and domains. The corresponding explanations and reasons, including another alternative method, should be used in conjunction with this annotation.
-
@SuppressWarnings: Indicates that the compiler does not generate a warning for one or more of the specified reasons.
-
@FunctionalInterface: This annotation represents a functional interface element. A functional interface is an interface that has only one abstract method (not the default). The compiler examines the annotated element and, if it does not, produces an error.
Java Annotations (annotation) Basic Learning