ArrayType
, DeclaredType
, Element
, ErrorType
, ExecutableElement
, ExecutableType
, IntersectionType
, ModuleElement
, NoType
, NullType
, PackageElement
, Parameterizable
, PrimitiveType
, QualifiedNameable
, RecordComponentElement
, ReferenceType
, TypeElement
, TypeMirror
, TypeParameterElement
, TypeVariable
, UnionType
, VariableElement
, WildcardType
public interface AnnotatedConstruct
In the definitions below, an annotation A has an annotation interface AI. If AI is a repeatable annotation interface, the type of the containing annotation is AIC.
Annotation A is directly present on a construct C if either:
Typically, if exactly one annotation of type AI appears in the source code of representation of C, then A is explicitly declared as applying to C. An annotation of type AI on a record component can be implicitly propagated down to affiliated mandated members. Type annotations modifying the type of a record component can be also propagated to mandated members. Propagation of the annotations to mandated members is governed by rules given in the The Java Language Specification (JLS 8.10.1). If there are multiple annotations of type AI present on C, then if AI is repeatable annotation interface, an annotation of type AIC is implicitly declared on C.
RuntimeVisibleAnnotations
(JVMS 4.7.16) or RuntimeVisibleParameterAnnotations
(JVMS 4.7.17) attributes of a class file. An annotation A is present on a construct C if either:
value
method of the directly present annotation of type AIC. @Inherited
Modifier and Type | Method | Description |
---|---|---|
<A extends Annotation> |
getAnnotation |
Returns this construct's annotation of the specified type if such an annotation is present, else null . |
List |
getAnnotationMirrors() |
Returns the annotations that are directly present on this construct. |
<A extends Annotation> |
getAnnotationsByType |
Returns annotations that are associated with this construct. |
List<? extends AnnotationMirror> getAnnotationMirrors()
<A extends Annotation> A getAnnotation(Class<A> annotationType)
null
. The annotation returned by this method could contain an element whose value is of type Class
. This value cannot be returned directly: information necessary to locate and load a class (such as the class loader to use) is not available, and the class might not be loadable at all. Attempting to read a Class
object by invoking the relevant method on the returned annotation will result in a MirroredTypeException
, from which the corresponding TypeMirror
may be extracted. Similarly, attempting to read a Class[]
-valued element will result in a MirroredTypesException
.
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation interfaces currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation interfaces.
A
- the annotation interfaceannotationType
- the Class
object corresponding to the annotation interfacenull
<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType)
getAnnotation(Class)
is that this method detects if its argument is a repeatable annotation interface, and if so, attempts to find one or more annotations of that type by "looking through" a container annotation. The annotations returned by this method could contain an element whose value is of type Class
. This value cannot be returned directly: information necessary to locate and load a class (such as the class loader to use) is not available, and the class might not be loadable at all. Attempting to read a Class
object by invoking the relevant method on the returned annotation will result in a MirroredTypeException
, from which the corresponding TypeMirror
may be extracted. Similarly, attempting to read a Class[]
-valued element will result in a MirroredTypesException
.
Note: This method is unlike others in this and related interfaces. It operates on runtime reflective information — representations of annotation interfaces currently loaded into the VM — rather than on the representations defined by and used throughout these interfaces. Consequently, calling methods on the returned annotation object can throw many of the exceptions that can be thrown when calling methods on an annotation object returned by core reflection. This method is intended for callers that are written to operate on a known, fixed set of annotation interfaces.
A
- the annotation interfaceannotationType
- the Class
object corresponding to the annotation interface
© 1993, 2023, 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.
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/lang/model/AnnotatedConstruct.html