java.lang.reflect
Interface AnnotatedElement

All Known Implementing Classes:
AccessibleObject, Class, Constructor, Field, Method, Package

public interface AnnotatedElement

Represents an annotated element of the program currently running in this JVM. This interface allows annotations to be read reflectively. All annotations returned by methods in this interface are serializable. If an annotation object returned by a method in this interface contains (directly or indirectly) one or more Class members that refer to a class that is not accessible in this JVM, attempting to read the class by calling the relevant Class-returning method on the returned annotation (or an annotation referred to by that annotation) will cause a TypeNotPresentException to be thrown.

Since:
1.5

Method Summary
<T extends java.lang.annotation.Annotation>
T
getAnnotation(Class<T> annotationType)
          Returns this element's annotation for the specified type if such an annotation is present, else null.
 java.lang.annotation.Annotation[] getAnnotations()
          Returns all annotations present on this element.
 java.lang.annotation.Annotation[] getDeclaredAnnotations()
          Returns all annotations that are directly present on this element.
 boolean isAnnotationPresent(Class<? extends java.lang.annotation.Annotation> annotationType)
          Returns true if an annotation for the specified type is present on this element, else false.
 

Method Detail

isAnnotationPresent

boolean isAnnotationPresent(Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations.

Parameters:
annotationType - the Class object corresponding to the annotation type
Returns:
true if an annotation for the specified annotation type is present on this element, else false
Throws:
NullPointerException - if annotationType is null
Since:
1.5

getAnnotation

<T extends java.lang.annotation.Annotation> T getAnnotation(Class<T> annotationType)
Returns this element's annotation for the specified type if such an annotation is present, else null.

Parameters:
annotationType - 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 annotationType is null
Since:
1.5

getAnnotations

java.lang.annotation.Annotation[] getAnnotations()
Returns all annotations present on this element. (Returns an array of length zero if this element has no annotations.)

Returns:
all annotations present on this element
Since:
1.5

getDeclaredAnnotations

java.lang.annotation.Annotation[] getDeclaredAnnotations()
Returns all annotations that are directly present on this element. Unlike the other methods in this interface, this method ignores inherited annotations. (Returns an array of length zero if no annotations are directly present on this element.)

Returns:
All annotations directly present on this element
Since:
1.5