Interface AnnotatedType
- All Superinterfaces:
AnnotatedElement
- All Known Subinterfaces:
AnnotatedArrayType
,AnnotatedParameterizedType
,AnnotatedTypeVariable
,AnnotatedWildcardType
AnnotatedType
represents the potentially annotated use of a type in the program currently running in this VM. The use may be of any type in the Java programming language, including an array type, a parameterized type, a type variable, or a wildcard type. Note that any annotations returned by methods on this interface aretype annotations (JLS9.7.4) as the entity being potentially annotated is a type.Method Summary
Modifier and TypeMethodDescriptiondefaultAnnotatedType
Returns the potentially annotated type that this type is a member of, if this type represents a nested type.<T extendsAnnotation>
TgetAnnotation
(Class<T> annotationClass) Returns this element's annotation for the specified type if such an annotation ispresent, else null.Returns annotations that arepresent on this element.Returns annotations that aredirectly present on this element.getType()
Returns the underlying type that this annotated type represents.Methods declared in interface java.lang.reflect.AnnotatedElement
getAnnotationsByType,getDeclaredAnnotation,getDeclaredAnnotationsByType,isAnnotationPresent
Method Details
getAnnotatedOwnerType
Returns the potentially annotated type that this type is a member of, if this type represents a nested type. For example, if this type is@TA O<T>.I<S>
, return a representation of@TA O<T>
.Returns
null
if thisAnnotatedType
represents a top-level class or interface, or a local or anonymous class, or a primitive type, or void.Returns
null
if thisAnnotatedType
is an instance ofAnnotatedArrayType
,AnnotatedTypeVariable
, orAnnotatedWildcardType
.- Implementation Requirements:
- This default implementation returns
null
and performs no other action. - Returns:
- an
AnnotatedType
object representing the potentially annotated type that this type is a member of, ornull
- Throws:
TypeNotPresentException
- if the owner type refers to a non-existent class or interface declarationMalformedParameterizedTypeException
- if the owner type refers to a parameterized type that cannot be instantiated for any reason- Since:
- 9
getType
Type getType()Returns the underlying type that this annotated type represents.- Returns:
- the type this annotated type represents
getAnnotation
Returns this element's annotation for the specified type if such an annotation ispresent, else null.Note that any annotation returned by this method is a type annotation.
- Specified by:
getAnnotation
in interfaceAnnotatedElement
- Type Parameters:
T
- the type of the annotation to query for and return if present- Parameters:
annotationClass
- the Class object corresponding to the annotation type- Returns:
- this element's annotation for the specified annotation type if present on this element, else null
- Throws:
NullPointerException
- if the given annotation class is null
getAnnotations
Annotation[] getAnnotations()Returns annotations that arepresent on this element. If there are no annotationspresent on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.Note that any annotations returned by this method are type annotations.
- Specified by:
getAnnotations
in interfaceAnnotatedElement
- Returns:
- annotations present on this element
getDeclaredAnnotations
Annotation[] getDeclaredAnnotations()Returns annotations that aredirectly present on this element. This method ignores inherited annotations. If there are no annotationsdirectly present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.Note that any annotations returned by this method are type annotations.
- Specified by:
getDeclaredAnnotations
in interfaceAnnotatedElement
- Returns:
- annotations directly present on this element