Java Utililty Methods Reflection Annotation

List of utility methods to do Reflection Annotation

Description

The list of methods to do Reflection Annotation are organized into topic(s).

Method

AnnotationgetAnnotation(Class annotationClass, Annotation[] annotations)
Searches for annotation instance of the type specified by annotationClass in the array of annotations.
for (Annotation a : annotations) {
    if (annotationClass.isInstance(a)) {
        return a;
return null;
TgetAnnotation(Class base, Class annotationClass)
get Annotation
T annotation = null;
annotation = base.getAnnotation(annotationClass);
if (null != annotation) {
    return annotation;
Class<?>[] implementees = base.getInterfaces();
for (int i = 0; null == annotation && i < implementees.length; i++) {
    annotation = implementees[i].getAnnotation(annotationClass);
...
AnnotationgetAnnotation(Class c, Class annotationClass)
Returns true if specified class is annotated with annotation of annotationClass type.
return c.getAnnotation(annotationClass);
AgetAnnotation(Class classForAnnotation, Class annotationClass)
Returns annotation for specified class.
if (classForAnnotation == null) {
    return null;
A result = classForAnnotation.getAnnotation(annotationClass);
if (result != null) {
    return result;
return getAnnotation(classForAnnotation.getSuperclass(), annotationClass);
...
AgetAnnotation(Class clazz, Class annotationClass)
get Annotation
return clazz.getAnnotation(annotationClass);
AgetAnnotation(Class clazz, Class annotationClass)
This is proxy ready implementation Class#getAnnotation(Class) .
final A annotation = clazz.getAnnotation(annotationClass);
if (annotation == null && clazz.isSynthetic()) { 
    return getAnnotation(clazz.getSuperclass(), annotationClass);
} else {
    return annotation;
AgetAnnotation(Class clazz, Class annotClass, boolean forceInherit)
get Annotation
boolean inherited = forceInherit || annotClass.isAnnotationPresent(Inherited.class);
LinkedList<Class<?>> workQueue = new LinkedList<Class<?>>();
workQueue.add(clazz);
while (!workQueue.isEmpty()) {
    clazz = workQueue.removeFirst();
    A result = clazz.getAnnotation(annotClass);
    if (result != null || !inherited) {
        return result;
...
RgetAnnotation(Class clazz, Class annotationClass)
get Annotation
return (R) findAnnotation(clazz, annotationClass, new HashSet<>());
TgetAnnotation(Class clazz, Class ann)
Inspects the class passed in for the class level annotation specified.
while (true) {
    T a = clazz.getAnnotation(ann);
    if (a != null)
        return a;
    if (!clazz.isInterface()) {
        Class<?>[] interfaces = clazz.getInterfaces();
        for (Class<?> inter : interfaces) {
            a = getAnnotation(inter, ann);
...
TgetAnnotation(Class clazz, Class annClazz)
get Annotation
while (clazz != null) {
    T ann = clazz.getAnnotation(annClazz);
    if (ann != null) {
        return ann;
    clazz = clazz.getSuperclass();
return null;
...