How I can do custom Java annotation with no attribute name inside parentheses?
I don't want this: @annotation_name(att=valor). I just want like in Servlets, i.e:
@WebServlet("/main")
Java Custom annotations or Java User-defined annotations are easy to create and use. The @interface element is used to declare an annotation. For example: @interface MyAnnotation{}
Annotations are used to provide supplemental information about a program. Annotations start with '@'. Annotations do not change the action of a compiled program. Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc.
Define the annotation with an attribute named value, then the attribute name can be omitted:
@interface CustomAnnotation { String value(); } This can be used like so:
@CustomAnnotation("/main") // ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With