Java annotation: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Added title. | Use this bot. Report bugs. | Suggested by Jay8g | #UCB_toolbar
 
(5 intermediate revisions by one other user not shown)
Line 42:
| <code>@FunctionalInterface</code> || <code>java.lang</code> || Marks an interface as intended to be a functional interface.
|-
| <code>@Override</code> || <code>java.lang</code> || ChecksMarks that the method is an [[Method overriding|overrideoverrides]] an ancestor class-defined method. Causes a [[compilation error]] if the method is not found in one of the [[parent class]]es or implemented [[Interface (Java)|interfaces]].
|-
| <code>@SafeVarargs</code> || <code>java.lang</code> || Suppress warnings for all callers of a method or constructor with a [[Generics in Java|generics]] [[Variadic function|varargs]] parameter, since Java 7.
Line 62:
 
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
| title = Jakarta Annotations API 1.3.5 API
| url = https://jakartaee.github.io/common-annotations-api/apidocs/
| publisher = [[Jakarta EE]]
| access-date = 2025-08-13
}}</ref><ref>{{cite web
| title = Jakarta Annotations
| url = https://jakarta.ee/specifications/annotations/3.0/annotations-spec-3.0.html
| publisher = [[Jakarta EE]]
Line 215 ⟶ 217:
 
<syntaxhighlight lang=Java>
package com.acme.proj.annotation;
 
import java.lang.annotation.Documented;
Line 226 ⟶ 228:
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.TYPE, ElementType.METHOD,
ElementType.CONSTRUCTOR, ElementType.ANNOTATION_TYPE,
ElementType.PACKAGE, ElementType.FIELD, ElementType.LOCAL_VARIABLE
})
@Inherited
 
public @interface Unfinished {
public enum Priority { LOW, MEDIUM, HIGH }
Line 243 ⟶ 246:
 
<syntaxhighlight lang=Java>
package com.acme.proj.annotation;
 
public @interface UnderConstruction {
Line 254 ⟶ 257:
 
<syntaxhighlight lang=Java>
package com.acme.proj.validators;
 
import javax.faces.application.FacesMessage;
Line 262 ⟶ 265:
import javax.faces.validator.ValidatorException;
 
import com.acme.proj.annotation.UnderConstruction;
import com.acme.proj.annotation.Unfinished;
import com.acme.proj.annotation.Unfinished.Priority;
import com.acme.proj.util.Util;
 
@UnderConstruction(owner = "Jon Doe")
public class DateValidator implements Validator {
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
throws ValidatorException {
String date = (String) value;
String errorLabel = "Please enter a valid date.";
Line 279 ⟶ 281:
 
if (!Util.validateAGivenDate(date)) {
@Unfinished(
changedBy = "Steve",
value = "whether to add message to context or not, confirm",
priority = Priority.HIGH
Line 320 ⟶ 323:
<syntaxhighlight lang=Java>
// This is the annotation being applied to a class
@TypeHeader(
developer = "Bob Bee",
lastModified = "2013-02-12",
teamMembers = { "Ann", "Dan", "Fran" },
meaningOfLife = 42
)
public class SetCustomAnnotation {
// Class contents go here