Content deleted Content added
Line 35:
}}</ref>
{| class="wikitable"
! Annotation !! Package !! Description
* <code>@Override</code> — Checks that the method is an [[Method overriding|override]]. Causes a [[compilation error]] if the method is not found in one of the [[parent class]]es or implemented [[Interface (Java)|interfaces]].▼
|-
|-
| <code>@FunctionalInterface</code> || <code>java.lang</code> || Marks an interface as intended to be a functional interface.
|-
▲
|-
|-
| <code>@SuppressWarnings</code> || <code>java.lang</code> || Instructs the compiler to suppress the [[compile time]] warnings specified in the annotation parameters.
|-
|-
| <code>@Inherited</code> || <code>java.lang.annotation</code> || Marks another annotation to be inherited to subclasses of annotated class (by default annotations are not inherited by subclasses).
|-
| <code>@Native</code> || <code>java.lang.annotation</code> || Marks a field defining a constant value as potentially being referenced from native code.
|-
| <code>@Repeatable</code> || <code>java.lang.annotation</code> || Marks another annotation as repeatable.
|-
|-
|}
In [[Jakarta EE]] (formerly Java Platform, Enterprise Edition), the following annotations also exist in <code>jakarta.annotation</code> (formerly <code>javax.annotation</code>):<ref>{{cite web
| url = https://jakartaee.github.io/common-annotations-api/apidocs/
| publisher = [[Jakarta EE]]
| access-date = 2025-08-13
}}</ref><ref>{{cite web
| url = https://jakarta.ee/specifications/annotations/3.0/annotations-spec-3.0.html
| publisher = [[Jakarta EE]]
| access-date = 2025-08-13
}}</ref>
{| class="wikitable"
▲* <code>@Retention</code> — Specifies how the marked annotation is stored, whether in code only, compiled into the class, or available at runtime through reflection.
! Annotation !! Package !! Description
▲* <code>@Documented</code> — Marks another annotation for inclusion in the documentation.
|-
▲* <code>@Target</code> — Marks another annotation to restrict what kind of Java elements the annotation may be applied to.
|-
| <code>@Resource</code> || <code>jakarta.annotation</code> || Marks a class, method, or field as a reference to a resource.
|-
| <code>@Resources</code> || <code>jakarta.annotation</code> || Declares reference to resources, as a container for multiple resource declarations.
▲* <code>@SafeVarargs</code> — Suppress warnings for all callers of a method or constructor with a [[Generics in Java|generics]] [[Variadic function|varargs]] parameter, since Java 7.
|-
| <code>@PostConstruct</code> || <code>jakarta.annotation</code> || Marks a method to indicate that it must be executed after dependency injection to perform initialization, i.e. the method must be invoked before the class is used.
|-
| <code>@PreDestroy</code> || <code>jakarta.annotation</code> || Marks a method as a callback notification to indicate the instance is in the process of being removed by the container, i.e. the method is used to release resources held by the instance.
|-
| <code>@Priority</code> || <code>jakarta.annotation</code> || Marks any program element to indicate in what order they should be used.
|-
| <code>@Nonnull</code> || <code>jakarta.annotation</code> || Marks any element that cannot be <code>null</code>.
|-
| <code>@Nullable</code> || <code>java.lang.annotation</code> || Marks any element that has the explicit possibility of being <code>null</code>.
|-
| <code>@RunAs</code> || <code>jakarta.annotation</code> || Defines the security role of the application during execution in a Jakarta EE container.
|-
| <code>@RolesAllowed</code> || <code>jakarta.annotation.security</code> || Marks a method to specify security roles permitted to access the method.
|-
| <code>@PermitAll</code> || <code>jakarta.annotation.security</code> || Marks a method to specify that all security roles may access the method.
|-
| <code>@DenyAll</code> || <code>jakarta.annotation.security</code> || Marks a method to specify that no security roles may access the method.
|-
| <code>@DeclareRoles</code> || <code>jakarta.annotation.security</code> || Specifies security roles used by the application.
|-
| <code>@DataSourceDefinition</code> || <code>jakarta.annotation.sql</code> || Defines a container <code>DataSource</code> that is registered with [[Java Naming and Directory Interface]] (JNDI).
|-
| <code>@DataSourceDefinitions</code> || <code>jakarta.annotation.sql</code> || Declares a container <code>DataSource</code>, acting as a container for multiple data source declarations.
|}
== Example ==
|