public interface AnnotatedElement
Represents an element that can be annotated. The methods of this interface provide reflection-based access to the annotations associated with a particular element, such as a class, field, method or package. Each annotation returned by these methods is both immutable and serializable. The returned arrays may be freely modified, without any effect on the arrays returned to future callers.
If an annotation refers to a type or enumeration constant that is
inaccessible, then a TypeNotPresentException
or
EnumConstantNotPresentException
will be thrown. Likewise,
invalid annotations will produce either a
AnnotationTypeMismatchException
or
IncompleteAnnotationException
.
Modifier and Type | Method and Description |
---|---|
<T extends Annotation> |
getAnnotation(Class<T> annotationClass)
Returns the element's annotation for the specified annotation type,
or
null if no such annotation exists. |
Annotation[] |
getAnnotations()
Returns all annotations associated with the element.
|
Annotation[] |
getDeclaredAnnotations()
Returns all annotations directly defined by the element.
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type is associated
with the element.
|
<T extends Annotation> T getAnnotation(Class<T> annotationClass)
null
if no such annotation exists.annotationClass
- the type of annotation to look for.null
if no such annotation exists.NullPointerException
- if the annotation class is null
.Annotation[] getAnnotations()
Annotation[] getDeclaredAnnotations()
boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
annotationClass
- the type of annotation to look for.