APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface AnnotationElement

permits AnnotationElementImpl
Known Direct Implementers
jdk.internal.classfile.impl.AnnotationImpl.AnnotationElementImpl
Imports
java.lang.classfile.constantpool.Utf8Entry, java.lang.constant.ClassDesc, jdk.internal.classfile.impl.AnnotationImpl, .TemporaryConstantPool

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.

Since
24
Java Virtual Machine Specification
4.7.16.1 The element_value structure
See Also
Annotation, Annotations in core reflection

Method Summary

Modifier and TypeMethod and Description
public Utf8Entry

Returns:

the element name
name
()

Returns the element name.

public static AnnotationElement

Returns:

an element-value pair
of
(Utf8Entry
the name of the key
name
,
AnnotationValue
the associated value
value
)

Returns an element-value pair.

public static AnnotationElement

Returns:

an element-value pair
of
(String
the name of the key
name
,
AnnotationValue
the associated value
value
)

Returns an element-value pair.

public static AnnotationElement

Returns:

an element-value pair for an annotation-valued element
ofAnnotation
(String
the name of the key
name
,
Annotation
the associated value
value
)

Returns an element-value pair for an annotation-valued element.

public static AnnotationElement

Returns:

an element-value pair for an array-valued element
ofArray
(String
the name of the key
name
,
AnnotationValue...
the associated values
values
)

Returns an element-value pair for an array-valued element.

public static AnnotationElement

Returns:

an element-value pair for a boolean-valued element
ofBoolean
(String
the name of the key
name
,
boolean
the associated value
value
)

Returns an element-value pair for a boolean-valued element.

public static AnnotationElement

Returns:

an element-value pair for a byte-valued element
ofByte
(String
the name of the key
name
,
byte
the associated value
value
)

Returns an element-value pair for a byte-valued element.

public static AnnotationElement

Returns:

an element-value pair for a char-valued element
ofChar
(String
the name of the key
name
,
char
the associated value
value
)

Returns an element-value pair for a char-valued element.

public static AnnotationElement

Returns:

an element-value pair for a class-valued element
ofClass
(String
the name of the key
name
,
ClassDesc
the associated value
value
)

Returns an element-value pair for a class-valued element.

public static AnnotationElement

Returns:

an element-value pair for a double-valued element
ofDouble
(String
the name of the key
name
,
double
the associated value
value
)

Returns an element-value pair for a double-valued element.

public static AnnotationElement

Returns:

an element-value pair for a float-valued element
ofFloat
(String
the name of the key
name
,
float
the associated value
value
)

Returns an element-value pair for a float-valued element.

public static AnnotationElement

Returns:

an element-value pair for an int-valued element
ofInt
(String
the name of the key
name
,
int
the associated value
value
)

Returns an element-value pair for an int-valued element.

public static AnnotationElement

Returns:

an element-value pair for a long-valued element
ofLong
(String
the name of the key
name
,
long
the associated value
value
)

Returns an element-value pair for a long-valued element.

public static AnnotationElement

Returns:

an element-value pair for a short-valued element
ofShort
(String
the name of the key
name
,
short
the associated value
value
)

Returns an element-value pair for a short-valued element.

public static AnnotationElement

Returns:

an element-value pair for a string-valued element
ofString
(String
the name of the key
name
,
String
the associated value
value
)

Returns an element-value pair for a string-valued element.

public AnnotationValue

Returns:

the element value
value
()

Returns the element value.

Method Detail

nameback to summary
public 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:Utf8Entry

the element name

ofback to summary
public static AnnotationElement of(Utf8Entry name, AnnotationValue value)

Returns an element-value pair.

Parameters
name:Utf8Entry

the name of the key

value:AnnotationValue

the associated value

Returns:AnnotationElement

an element-value pair

ofback to summary
public static AnnotationElement of(String name, AnnotationValue value)

Returns an element-value pair.

Parameters
name:String

the name of the key

value:AnnotationValue

the associated value

Returns:AnnotationElement

an element-value pair

ofAnnotationback to summary
public static AnnotationElement ofAnnotation(String name, Annotation value)

Returns an element-value pair for an annotation-valued element.

Parameters
name:String

the name of the key

value:Annotation

the associated value

Returns:AnnotationElement

an element-value pair for an annotation-valued element

See Also
AnnotationValue::ofAnnotation
ofArrayback to summary
public static AnnotationElement ofArray(String name, AnnotationValue... values)

Returns an element-value pair for an array-valued element.

Parameters
name:String

the name of the key

values:AnnotationValue[]

the associated values

Returns:AnnotationElement

an element-value pair for an array-valued element

Exceptions
IllegalArgumentException:
if the number of associated values exceeds the limit of u2
See Also
AnnotationValue::ofArray
ofBooleanback to summary
public static AnnotationElement ofBoolean(String name, boolean value)

Returns an element-value pair for a boolean-valued element.

Parameters
name:String

the name of the key

value:boolean

the associated value

Returns:AnnotationElement

an element-value pair for a boolean-valued element

See Also
AnnotationValue::ofBoolean
ofByteback to summary
public static AnnotationElement ofByte(String name, byte value)

Returns an element-value pair for a byte-valued element.

Parameters
name:String

the name of the key

value:byte

the associated value

Returns:AnnotationElement

an element-value pair for a byte-valued element

See Also
AnnotationValue::ofByte
ofCharback to summary
public static AnnotationElement ofChar(String name, char value)

Returns an element-value pair for a char-valued element.

Parameters
name:String

the name of the key

value:char

the associated value

Returns:AnnotationElement

an element-value pair for a char-valued element

See Also
AnnotationValue::ofChar
ofClassback to summary
public static AnnotationElement ofClass(String name, ClassDesc value)

Returns an element-value pair for a class-valued element.

Parameters
name:String

the name of the key

value:ClassDesc

the associated value

Returns:AnnotationElement

an element-value pair for a class-valued element

See Also
AnnotationValue::ofClass
ofDoubleback to summary
public static AnnotationElement ofDouble(String name, double value)

Returns an element-value pair for a double-valued element.

Parameters
name:String

the name of the key

value:double

the associated value

Returns:AnnotationElement

an element-value pair for a double-valued element

See Also
AnnotationValue::ofDouble
ofFloatback to summary
public static AnnotationElement ofFloat(String name, float value)

Returns an element-value pair for a float-valued element.

Parameters
name:String

the name of the key

value:float

the associated value

Returns:AnnotationElement

an element-value pair for a float-valued element

See Also
AnnotationValue::ofFloat
ofIntback to summary
public static AnnotationElement ofInt(String name, int value)

Returns an element-value pair for an int-valued element.

Parameters
name:String

the name of the key

value:int

the associated value

Returns:AnnotationElement

an element-value pair for an int-valued element

See Also
AnnotationValue::ofInt
ofLongback to summary
public static AnnotationElement ofLong(String name, long value)

Returns an element-value pair for a long-valued element.

Parameters
name:String

the name of the key

value:long

the associated value

Returns:AnnotationElement

an element-value pair for a long-valued element

See Also
AnnotationValue::ofLong
ofShortback to summary
public static AnnotationElement ofShort(String name, short value)

Returns an element-value pair for a short-valued element.

Parameters
name:String

the name of the key

value:short

the associated value

Returns:AnnotationElement

an element-value pair for a short-valued element

See Also
AnnotationValue::ofShort
ofStringback to summary
public static AnnotationElement ofString(String name, String value)

Returns an element-value pair for a string-valued element.

Parameters
name:String

the name of the key

value:String

the associated value

Returns:AnnotationElement

an element-value pair for a string-valued element

See Also
AnnotationValue::ofString
valueback to summary
public AnnotationValue value()

Returns the element value.

Returns:AnnotationValue

the element value