Annotation (Java SE 22 & JDK 22)
Description: declaration: module: java.base, package: java.lang.classfile, interface: Annotation
Keywords: java.lang.classfile.Annotation interface

Module java.base
Package java.lang.classfilePREVIEW

# Interface Annotation

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

All Known Subinterfaces:
  `TypeAnnotationPREVIEW`

public sealed interface Annotation extends WritableElementPREVIEW<AnnotationPREVIEW> permits TypeAnnotationPREVIEW (not exhaustive)
`Annotation` is a preview API of the Java platform.
Programs can only use `Annotation` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Models an annotation on a declaration.

Sealed Class Hierarchy Graph:
Since:
  22
See Also:
  - `AnnotationElement`PREVIEW
  - `AnnotationValue`PREVIEW
  - `RuntimeVisibleAnnotationsAttribute`PREVIEW
  - `RuntimeInvisibleAnnotationsAttribute`PREVIEW
  - `RuntimeVisibleParameterAnnotationsAttribute`PREVIEW
  - `RuntimeInvisibleParameterAnnotationsAttribute`PREVIEW

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Utf8EntryPREVIEW`
  `className()`
  Returns the class of the annotation.
  `default ClassDesc`
  `classSymbol()`
  Returns the class of the annotation, as a symbolic descriptor.
  `List<AnnotationElementPREVIEW>`
  `elements()`
  Returns the elements of the annotation.
  `static AnnotationPREVIEW`
  `of(Utf8EntryPREVIEW annotationClass, AnnotationElementPREVIEW... elements)`
  Returns an annotation.
  `static AnnotationPREVIEW`
  `of(Utf8EntryPREVIEW annotationClass, List<AnnotationElementPREVIEW> elements)`
  Returns an annotation.
  `static AnnotationPREVIEW`
  `of(ClassDesc annotationClass, AnnotationElementPREVIEW... elements)`
  Returns an annotation.
  `static AnnotationPREVIEW`
  `of(ClassDesc annotationClass, List<AnnotationElementPREVIEW> elements)`
  Returns an annotation.

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

  `writeTo`

- ## Method Details

  - ### className

    Utf8EntryPREVIEW className()
    Returns the class of the annotation.
    Returns:
      the class of the annotation

  - ### classSymbol

    default ClassDesc classSymbol()
    Returns the class of the annotation, as a symbolic descriptor.
    Returns:
      the class of the annotation, as a symbolic descriptor

  - ### elements

    List<AnnotationElementPREVIEW> elements()
    Returns the elements of the annotation.
    Returns:
      the elements of the annotation

  - ### of

    static AnnotationPREVIEW of(Utf8EntryPREVIEW annotationClass, List<AnnotationElementPREVIEW> elements)
    Returns an annotation.
    Parameters:
      `annotationClass` - the class of the annotation
      `elements` - the elements of the annotation
    Returns:
      an annotation

  - ### of

    static AnnotationPREVIEW of(Utf8EntryPREVIEW annotationClass, AnnotationElementPREVIEW... elements)
    Returns an annotation.
    Parameters:
      `annotationClass` - the class of the annotation
      `elements` - the elements of the annotation
    Returns:
      an annotation

  - ### of

    static AnnotationPREVIEW of(ClassDesc annotationClass, List<AnnotationElementPREVIEW> elements)
    Returns an annotation.
    Parameters:
      `annotationClass` - the class of the annotation
      `elements` - the elements of the annotation
    Returns:
      an annotation

  - ### of

    static AnnotationPREVIEW of(ClassDesc annotationClass, AnnotationElementPREVIEW... elements)
    Returns an annotation.
    Parameters:
      `annotationClass` - the class of the annotation
      `elements` - the elements of the annotation
    Returns:
      an annotation