APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface Annotation

permits AnnotationImpl
Known Direct Implementers
jdk.internal.classfile.impl.AnnotationImpl
Imports
java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute, .RuntimeInvisibleParameterAnnotationsAttribute, .RuntimeVisibleAnnotationsAttribute, .RuntimeVisibleParameterAnnotationsAttribute, java.lang.classfile.constantpool.Utf8Entry, java.lang.constant.ClassDesc, java.util.List, jdk.internal.classfile.impl.AnnotationImpl, .TemporaryConstantPool, .Util

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
java.lang.annotation.Annotation, Annotations in core reflection, TypeAnnotation, RuntimeVisibleAnnotationsAttribute, RuntimeInvisibleAnnotationsAttribute, RuntimeVisibleParameterAnnotationsAttribute, RuntimeInvisibleParameterAnnotationsAttribute

Method Summary

Modifier and TypeMethod and Description
public Utf8Entry

Returns:

the constant pool entry holding the descriptor string of the annotation interface
className
()

Returns the constant pool entry holding the descriptor string of the annotation interface.

public default ClassDesc

Returns:

the annotation interface, as a symbolic descriptor
classSymbol
()

Returns the annotation interface, as a symbolic descriptor.

public List<AnnotationElement>

Returns:

the element-value pairs of the annotation
elements
()

Returns the element-value pairs of the annotation.

public static Annotation

Returns:

an annotation
of
(Utf8Entry
the constant pool entry holding the descriptor string of the annotation interface
annotationClass
,
List<AnnotationElement>
the element-value pairs of the annotation
elements
)

Returns an annotation.

public static Annotation

Returns:

an annotation
of
(Utf8Entry
the constant pool entry holding the descriptor string of the annotation interface
annotationClass
,
AnnotationElement...
the element-value pairs of the annotation
elements
)

Returns an annotation.

public static Annotation

Returns:

an annotation
of
(ClassDesc
the descriptor of the annotation interface
annotationClass
,
List<AnnotationElement>
the element-value pairs of the annotation
elements
)

Returns an annotation.

public static Annotation

Returns:

an annotation
of
(ClassDesc
the descriptor of the annotation interface
annotationClass
,
AnnotationElement...
the element-value pairs of the annotation
elements
)

Returns an annotation.

Method Detail

classNameback to summary
public Utf8Entry className()

Returns the constant pool entry holding the descriptor string of the annotation interface.

Returns:Utf8Entry

the constant pool entry holding the descriptor string of the annotation interface

See Also
java.lang.annotation.Annotation#annotationType()
classSymbolback to summary
public default ClassDesc classSymbol()

Returns the annotation interface, as a symbolic descriptor.

Returns:ClassDesc

the annotation interface, as a symbolic descriptor

See Also
java.lang.annotation.Annotation#annotationType()
elementsback to summary
public List<AnnotationElement> elements()

Returns the element-value pairs of the annotation.

Returns:List<AnnotationElement>

the element-value pairs of the annotation

ofback to summary
public static Annotation of(Utf8Entry annotationClass, List<AnnotationElement> elements)

Returns an annotation.

Parameters
annotationClass:Utf8Entry

the constant pool entry holding the descriptor string of the annotation interface

elements:List<AnnotationElement>

the element-value pairs of the annotation

Returns:Annotation

an annotation

Exceptions
IllegalArgumentException:
if the number of pairs exceeds the limit of u2
ofback to summary
public static Annotation of(Utf8Entry annotationClass, AnnotationElement... elements)

Returns an annotation.

Parameters
annotationClass:Utf8Entry

the constant pool entry holding the descriptor string of the annotation interface

elements:AnnotationElement[]

the element-value pairs of the annotation

Returns:Annotation

an annotation

Exceptions
IllegalArgumentException:
if the number of pairs exceeds the limit of u2
ofback to summary
public static Annotation of(ClassDesc annotationClass, List<AnnotationElement> elements)

Returns an annotation.

Parameters
annotationClass:ClassDesc

the descriptor of the annotation interface

elements:List<AnnotationElement>

the element-value pairs of the annotation

Returns:Annotation

an annotation

Exceptions
IllegalArgumentException:
if the number of pairs exceeds the limit of u2
ofback to summary
public static Annotation of(ClassDesc annotationClass, AnnotationElement... elements)

Returns an annotation.

Parameters
annotationClass:ClassDesc

the descriptor of the annotation interface

elements:AnnotationElement[]

the element-value pairs of the annotation

Returns:Annotation

an annotation

Exceptions
IllegalArgumentException:
if the number of pairs exceeds the limit of u2