Java Define Your Own Annotation
Annotations offer an alternative to the use of xml descriptors and marker interfaces.
Java define your own annotation. This class is the one we re going to extend to create our own annotation processor. The annotation processing api is located in the javax annotation processing package. Annotations are a powerful part of java but most times we tend to be the users rather than the creators of annotations.
An annotation is defined with the interface keyword instead of class or interface. The main interface that you ll have to implement is the processor interface which has a partial implementation in the form of abstractprocessor class. Setting up the project.
An annotation always starts with the symbol followed by the annotation name. The type is the actual construct used and the annotation is the specific usage of that type. Annotations in java are used to provide additional information so it is an alternative option for xml and java marker interfaces.
Now we can use our own myservice annotations to annotate our services. We also added both spring annotations to our annotation. Annotation type is used for defining an annotation.
The standard java annotation retention is used to indicate that the annotation should be processable at runtime. For example it is not difficult to find java source code that includes the. Attached with class interface methods or fields to indicate some additional information which can be used by java compiler and jvm.
They are a powerful part of java and were added in jdk5. We will discuss this with the help of an example later in this same post. Java annotations are a mechanism for adding metadata information to our source code.