Spec-Zone.ru › OpenJDK 27

Interface Annotation

public sealed interface Annotation
Models an annotation structure (JVMS §4.7.16) or part of a type_annotation structure (JVMS §4.7.20). This model indicates the interface of the annotation and a set of element-value pairs.

This model can reconstruct an annotation, given the location of the modeled structure in the class file and the definition of the annotation interface.

Two Annotation objects should be compared using the equals method.

API Note:
For Java programs, the location of the modeled structure indicates the source code element or type (JLS §9.7.4) on which the reconstructed annotation appears, and the annotation interface definition determines whether the reconstructed annotation has elements with default values (JLS §9.6.2), and whether the reconstructed annotation is a container annotation for multiple annotations (JLS §9.7.5).
Since:
24
See Also:
  • Annotation
  • Annotations in core reflection
  • TypeAnnotation
  • RuntimeVisibleAnnotationsAttribute
  • RuntimeInvisibleAnnotationsAttribute
  • RuntimeVisibleParameterAnnotationsAttribute
  • RuntimeInvisibleParameterAnnotationsAttribute

Method Summary

Modifier and Type Method Description
Utf8Entry className()
Returns the constant pool entry holding the descriptor string of the annotation interface.
default ClassDesc classSymbol()
Returns the annotation interface, as a symbolic descriptor.
List<AnnotationElement> elements()
Returns the element-value pairs of the annotation.
static Annotation of(Utf8Entry annotationClass, AnnotationElement... elements)
Returns an annotation.
static Annotation of(Utf8Entry annotationClass, List<AnnotationElement> elements)
Returns an annotation.
static Annotation of(ClassDesc annotationClass, AnnotationElement... elements)
Returns an annotation.
static Annotation of(ClassDesc annotationClass, List<AnnotationElement> elements)
Returns an annotation.

Method Details

className

Utf8Entry className()
Returns the constant pool entry holding the descriptor string of the annotation interface.
Returns:
the constant pool entry holding the descriptor string of the annotation interface
See Also:
  • Annotation.annotationType()

classSymbol

default ClassDesc classSymbol()
Returns the annotation interface, as a symbolic descriptor.
Returns:
the annotation interface, as a symbolic descriptor
See Also:
  • Annotation.annotationType()

elements

List<AnnotationElement> elements()
Returns the element-value pairs of the annotation.
Returns:
the element-value pairs of the annotation

of

static Annotation of(Utf8Entry annotationClass, List<AnnotationElement> elements)
Returns an annotation.
Parameters:
annotationClass - the constant pool entry holding the descriptor string of the annotation interface
elements - the element-value pairs of the annotation
Returns:
an annotation
Throws:
IllegalArgumentException - if the number of pairs exceeds the limit of u2

of

static Annotation of(Utf8Entry annotationClass, AnnotationElement... elements)
Returns an annotation.
Parameters:
annotationClass - the constant pool entry holding the descriptor string of the annotation interface
elements - the element-value pairs of the annotation
Returns:
an annotation
Throws:
IllegalArgumentException - if the number of pairs exceeds the limit of u2

of

static Annotation of(ClassDesc annotationClass, List<AnnotationElement> elements)
Returns an annotation.
Parameters:
annotationClass - the descriptor of the annotation interface
elements - the element-value pairs of the annotation
Returns:
an annotation
Throws:
IllegalArgumentException - if the number of pairs exceeds the limit of u2

of

static Annotation of(ClassDesc annotationClass, AnnotationElement... elements)
Returns an annotation.
Parameters:
annotationClass - the descriptor of the annotation interface
elements - the element-value pairs of the annotation
Returns:
an annotation
Throws:
IllegalArgumentException - if the number of pairs exceeds the limit of u2

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 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.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API