public class AnnotationUtils
extends java.lang.Object
Constructor and Description |
---|
AnnotationUtils() |
Modifier and Type | Method and Description |
---|---|
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
Find a single
Annotation of annotationType from the supplied Class ,
traversing its interfaces and superclasses if no annotation can be found on the given class itself. |
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Class<?> clazz, java.lang.Class<A> annotationType)
Annotation
of annotationType
from the supplied Class
,
traversing its interfaces and superclasses if no annotation can be found on the given class itself.
This method explicitly handles class-level annotations which are not declared as
inherited
as well as annotations on interfaces.
The algorithm operates as follows: Searches for an annotation on the given class and returns it if found. Else searches all interfaces that the given class declares, returning the annotation from the first matching candidate, if any. Else proceeds with introspection of the superclass of the given class, checking the superclass itself; if no annotation found there, proceeds with the interfaces that the superclass declares. Recurring up through the entire superclass hierarchy if no match is found.
clazz
- the class to look for annotations onannotationType
- the annotation class to look fornull
if none found