Java Reflection Annotation getAnnotation(Class cls, Annotation... annotations)

Here you can find the source of getAnnotation(Class cls, Annotation... annotations)

Description

get Annotation

License

Apache License

Declaration

public static <T> T getAnnotation(Class<T> cls, Annotation... annotations) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.annotation.Annotation;

public class Main {
    public static <T> T getAnnotation(Class<T> cls, Annotation... annotations) {
        if (annotations == null) {
            return null;
        }//from w  w w  .  j  av a2  s . com
        for (Annotation annotation : annotations) {
            if (cls.isAssignableFrom(annotation.getClass())) {
                return (T) annotation;
            }
        }
        return null;
    }
}

Related

  1. getAnnotation(Class annotation, Class ownerClass, Method method)
  2. getAnnotation(Class annotationClass, Class cls)
  3. getAnnotation(Class annotationType, AnnotatedElement... objects)
  4. getAnnotation(Class cl, Object o)
  5. getAnnotation(Class clazz, Method method, int parameterIndex)
  6. getAnnotation(Class cls, Method... methods)
  7. getAnnotation(Class lookingFor, Annotation[] annotations)
  8. getAnnotation(Enum enumConstant, Class annotationClass)
  9. getAnnotation(final AnnotatedElement annotatedElement, final Class annotationClass)