Java Reflection Annotation getAnnotationByType(AnnotatedElement element, Class annotationType)

Here you can find the source of getAnnotationByType(AnnotatedElement element, Class annotationType)

Description

get Annotation By Type

License

Open Source License

Declaration

public static Annotation getAnnotationByType(AnnotatedElement element, Class annotationType) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

public class Main {
    public static Annotation getAnnotationByType(AnnotatedElement element, Class annotationType) {
        Annotation[] annotations = element.getAnnotations();
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationType)) {
                return annotation;
            }/*from   w w w .  j a  v  a  2s.  com*/
        }
        return null;
    }
}

Related

  1. getAnnotationAttribute(final Annotation anno, final String attrName, final Class attrType)
  2. getAnnotationAttributes(Annotation annotation)
  3. getAnnotationAttributes(Annotation annotation)
  4. getAnnotationAttributes(final Annotation annotation)
  5. getAnnotationAttributeValue(final Annotation annotation, final String attributeName)
  6. getAnnotationByType(List annotations, Class annotationType)
  7. getAnnotationClass(Annotation a)
  8. getAnnotationClass(Annotation annotation)
  9. getAnnotationClass(Class clazz, Class annotation)