java.lang.reflect
Interface AnnotatedElement

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

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.
 

Method Detail

getAnnotation

<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.

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.

getAnnotations

Annotation[] getAnnotations()
Returns all annotations associated with the element. If there are no annotations associated with the element, then a zero-length array will be returned. The returned array may be modified by the client code, but this will have no effect on the annotation content of the element, and hence no effect on the return value of this method for future callers.

Returns:
this element's annotations.

getDeclaredAnnotations

Annotation[] getDeclaredAnnotations()
Returns all annotations directly defined by the element. If there are no annotations directly associated with the element, then a zero-length array will be returned. The returned array may be modified by the client code, but this will have no effect on the annotation content of this class, and hence no effect on the return value of this method for future callers.

Returns:
the annotations directly defined by the element.
Since:
1.5

isAnnotationPresent

boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type is associated with the element. This is primarily a short-hand for using marker annotations.

Parameters:
annotationClass - the type of annotation to look for.
Returns:
true if an annotation exists for the specified type.
Since:
1.5