java.lang.reflect
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
.
Since: 1.5
Method Summary | |
---|---|
<T extends Annotation> T | 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. |
null
if no such annotation exists.
Parameters: annotationClass the type of annotation to look for.
Returns: this element's annotation for the specified type, or
null
if no such annotation exists.
Throws: NullPointerException if the annotation class is null
.
Returns: this element's annotations.
Returns: the annotations directly defined by the element.
Since: 1.5
Parameters: annotationClass the type of annotation to look for.
Returns: true if an annotation exists for the specified type.
Since: 1.5