Java Reflection Annotation Find findAnnotation(Class aClass, Class annotationClass)

Here you can find the source of findAnnotation(Class aClass, Class annotationClass)

Description

Finds an annotation of the class aClass by looking for an annotation matching the class annotationClass

License

Open Source License

Parameter

Parameter Description
aClass a parameter
annotationClass a parameter

Declaration

public static Annotation findAnnotation(Class<?> aClass, Class<? extends Annotation> annotationClass) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU Lesser General Public License as published by

import java.lang.annotation.Annotation;

public class Main {
    /**//from   w ww. j a  va 2  s  .  c om
     * Finds an annotation of the class aClass by looking for an annotation matching the class annotationClass
     *
     * @param aClass
     * @param annotationClass
     * @return
     */
    public static Annotation findAnnotation(Class<?> aClass, Class<? extends Annotation> annotationClass) {
        for (Annotation annotation : aClass.getAnnotations()) {
            if (annotation.annotationType().equals(annotationClass)) {
                return annotation;
            }
        }
        return null;
    }

    public static Annotation findAnnotation(Object object, Class<? extends Annotation> annotationClass) {
        return findAnnotation(object.getClass(), annotationClass);
    }
}

Related

  1. findAnnotation(Annotation parentAnnotation, Class annotationType)
  2. findAnnotation(Annotation[] parameterAnnotations, Class targetAnnotation)
  3. findAnnotation(Annotation[] searchList, Class annotation)
  4. findAnnotation(Class clazz, Class annotationType)
  5. findAnnotation(Class clazz, Class annotationType)
  6. findAnnotation(Class classy, Class targetAnnotation)
  7. findAnnotation(Class clazz, Class annotationClass, Set> set)
  8. findAnnotation(Class clazz, Class annotationClass)
  9. findAnnotation(Class clazz, Class annotationType)