Module java.base
Package java.lang.classfilePREVIEW

# Interface AnnotationElement

All Superinterfaces:
  `ClassFileElementPREVIEW`, `WritableElementPREVIEW<AnnotationElementPREVIEW>`

public sealed interface AnnotationElement extends WritableElementPREVIEW<AnnotationElementPREVIEW>
`AnnotationElement` is a preview API of the Java platform.
Programs can only use `AnnotationElement` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models a key-value pair of an annotation.

Since:
  22
See Also:
  - `Annotation`PREVIEW
  - `AnnotationValue`PREVIEW

- ## Method Summary

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

  ### Methods declared in interface java.lang.classfile.WritableElementPREVIEW

  `writeTo`

- ## Method Details

  - ### name

    Utf8EntryPREVIEW name()
    Returns the element name.
    Returns:
      the element name

  - ### value

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

  - ### of

    static AnnotationElementPREVIEW of(Utf8EntryPREVIEW name, AnnotationValuePREVIEW value)
    Returns an annotation key-value pair.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair

  - ### of

    static AnnotationElementPREVIEW of(String name, AnnotationValuePREVIEW value)
    Returns an annotation key-value pair.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair

  - ### ofClass

    static AnnotationElementPREVIEW ofClass(String name, ClassDesc value)
    Returns an annotation key-value pair for a class-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a class-valued annotation

  - ### ofString

    static AnnotationElementPREVIEW ofString(String name, String value)
    Returns an annotation key-value pair for a string-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a string-valued annotation

  - ### ofLong

    static AnnotationElementPREVIEW ofLong(String name, long value)
    Returns an annotation key-value pair for a long-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a long-valued annotation

  - ### ofInt

    static AnnotationElementPREVIEW ofInt(String name, int value)
    Returns an annotation key-value pair for an int-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for an int-valued annotation

  - ### ofChar

    static AnnotationElementPREVIEW ofChar(String name, char value)
    Returns an annotation key-value pair for a char-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a char-valued annotation

  - ### ofShort

    static AnnotationElementPREVIEW ofShort(String name, short value)
    Returns an annotation key-value pair for a short-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a short-valued annotation

  - ### ofByte

    static AnnotationElementPREVIEW ofByte(String name, byte value)
    Returns an annotation key-value pair for a byte-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a byte-valued annotation

  - ### ofBoolean

    static AnnotationElementPREVIEW ofBoolean(String name, boolean value)
    Returns an annotation key-value pair for a boolean-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a boolean-valued annotation

  - ### ofDouble

    static AnnotationElementPREVIEW ofDouble(String name, double value)
    Returns an annotation key-value pair for a double-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a double-valued annotation

  - ### ofFloat

    static AnnotationElementPREVIEW ofFloat(String name, float value)
    Returns an annotation key-value pair for a float-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for a float-valued annotation

  - ### ofAnnotation

    static AnnotationElementPREVIEW ofAnnotation(String name, AnnotationPREVIEW value)
    Returns an annotation key-value pair for an annotation-valued annotation.
    Parameters:
      `name` - the name of the key
      `value` - the associated value
    Returns:
      an annotation key-value pair for an annotation-valued annotation

  - ### ofArray

    static AnnotationElementPREVIEW ofArray(String name, AnnotationValuePREVIEW... values)
    Returns an annotation key-value pair for an array-valued annotation.
    Parameters:
      `name` - the name of the key
      `values` - the associated values
    Returns:
      an annotation key-value pair for an array-valued annotation