W3cubDocs

/OpenJDK 25

Interface AnnotationElement

public sealed interface AnnotationElement
Models an element-value pair in the element_value_pairs table in the annotation structure defined in JVMS 4.7.16 or the type_annotation structure defined in JVMS 4.7.20.

Two AnnotationElement objects should be compared using the equals method.

See Java Virtual Machine Specification:
4.7.16.1 The element_value structure
Since:
24
See Also:

Method Summary

Modifier and Type Method Description
Utf8Entry name()
Returns the element name.
static AnnotationElement of(Utf8Entry name, AnnotationValue value)
Returns an element-value pair.
static AnnotationElement of(String name, AnnotationValue value)
Returns an element-value pair.
static AnnotationElement ofAnnotation(String name, Annotation value)
Returns an element-value pair for an annotation-valued element.
static AnnotationElement ofArray(String name, AnnotationValue... values)
Returns an element-value pair for an array-valued element.
static AnnotationElement ofBoolean(String name, boolean value)
Returns an element-value pair for a boolean-valued element.
static AnnotationElement ofByte(String name, byte value)
Returns an element-value pair for a byte-valued element.
static AnnotationElement ofChar(String name, char value)
Returns an element-value pair for a char-valued element.
static AnnotationElement ofClass(String name, ClassDesc value)
Returns an element-value pair for a class-valued element.
static AnnotationElement ofDouble(String name, double value)
Returns an element-value pair for a double-valued element.
static AnnotationElement ofFloat(String name, float value)
Returns an element-value pair for a float-valued element.
static AnnotationElement ofInt(String name, int value)
Returns an element-value pair for an int-valued element.
static AnnotationElement ofLong(String name, long value)
Returns an element-value pair for a long-valued element.
static AnnotationElement ofShort(String name, short value)
Returns an element-value pair for a short-valued element.
static AnnotationElement ofString(String name, String value)
Returns an element-value pair for a string-valued element.
AnnotationValue value()
Returns the element value.

Method Details

name

Utf8Entry name()
Returns the element name.
API Note:
In Java source code, by convention, the name of the sole element in a single-element annotation interface is value. (JLS 9.6.1) This is the case for single-element annotations (JLS 9.7.3) and container annotations for multiple annotations (JLS 9.6.3).
Returns:
the element name

value

AnnotationValue value()
Returns the element value.
Returns:
the element value

of

static AnnotationElement of(Utf8Entry name, AnnotationValue value)
Returns an element-value pair.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair

of

static AnnotationElement of(String name, AnnotationValue value)
Returns an element-value pair.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair

ofClass

static AnnotationElement ofClass(String name, ClassDesc value)
Returns an element-value pair for a class-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a class-valued element
See Also:

ofString

static AnnotationElement ofString(String name, String value)
Returns an element-value pair for a string-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a string-valued element
See Also:

ofLong

static AnnotationElement ofLong(String name, long value)
Returns an element-value pair for a long-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a long-valued element
See Also:

ofInt

static AnnotationElement ofInt(String name, int value)
Returns an element-value pair for an int-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for an int-valued element
See Also:

ofChar

static AnnotationElement ofChar(String name, char value)
Returns an element-value pair for a char-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a char-valued element
See Also:

ofShort

static AnnotationElement ofShort(String name, short value)
Returns an element-value pair for a short-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a short-valued element
See Also:

ofByte

static AnnotationElement ofByte(String name, byte value)
Returns an element-value pair for a byte-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a byte-valued element
See Also:

ofBoolean

static AnnotationElement ofBoolean(String name, boolean value)
Returns an element-value pair for a boolean-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a boolean-valued element
See Also:

ofDouble

static AnnotationElement ofDouble(String name, double value)
Returns an element-value pair for a double-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a double-valued element
See Also:

ofFloat

static AnnotationElement ofFloat(String name, float value)
Returns an element-value pair for a float-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for a float-valued element
See Also:

ofAnnotation

static AnnotationElement ofAnnotation(String name, Annotation value)
Returns an element-value pair for an annotation-valued element.
Parameters:
name - the name of the key
value - the associated value
Returns:
an element-value pair for an annotation-valued element
See Also:

ofArray

static AnnotationElement ofArray(String name, AnnotationValue... values)
Returns an element-value pair for an array-valued element.
Parameters:
name - the name of the key
values - the associated values
Returns:
an element-value pair for an array-valued element
See Also:

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/AnnotationElement.html