| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/Java_annotation |
In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code, like an attribute. Classes, methods, variables, parameters and Java packages may be annotated. Like Javadoc tags, Java annotations can be read from source files. Unlike Javadoc tags, Java annotations can also be embedded in and read from Java class files generated by the Java compiler. This allows annotations to be retained by the Java virtual machine at run-time and read via reflection. It is possible to create meta-annotations out of the existing ones in Java.
@FunctionalInterfaceIn Jakarta EE (formerly Java Platform, Enterprise Edition), the following annotations also exist in jakarta.annotation (formerly javax.annotation):
| Annotation | Package | Description |
|---|---|---|
| @Resources | jakarta.annotation | Declares reference to resources, as a container for multiple resource declarations. |
| @Priority | jakarta.annotation | Marks any program element to indicate in what order they should be used. |
| @RunAs | jakarta.annotation | Defines the security role of the application during execution in a Jakarta EE container. |
| @DenyAll | jakarta.annotation.security | Marks a method to specify that no security roles may access the method. |
| @DataSourceDefinitions | jakarta.annotation.sql | Declares a container DataSource, acting as a container for multiple data source declarations. |
There was previously an annotation, // @Twizzle is an annotation to method toggle(). @Twizzle publicvoidtoggle(){ } // Declares the annotation Twizzle. public@interfaceTwizzle{ }
Annotations may include a set of key-value pairs, which are modeled as methods of the annotation type. Each method declaration defines an element of the annotation type. Method declarations must not have any parameters or a throws clause. Return types are restricted to primitives, // Same as: @Edible(value = true) @Edible(true) Itemitem=newCarrot(); public@interfaceEdible{ booleanvalue()defaultfalse; } @Author(first="Oompah",last="Loompah") Bookbook=newBook(); public@interfaceAuthor{ Stringfirst(); Stringlast(); }
Annotations themselves may be annotated to indicate where and when they can be used:
| View original on Wikipedia | Back | FazBrowse Home |