Java Reflection Annotation getAnnotationByType(List annotations, Class annotationType)

Here you can find the source of getAnnotationByType(List annotations, Class annotationType)

Description

get Annotation By Type

License

MIT License

Declaration

public static Annotation getAnnotationByType(List<Annotation> annotations, Class<?> annotationType) 

Method Source Code


//package com.java2s;
/*//  www  .  j  a v  a2  s.  co  m
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

import java.lang.annotation.Annotation;

import java.util.List;

public class Main {
    public static final Annotation[] NO_ANNOTATIONS = new Annotation[0];

    public static Annotation getAnnotationByType(List<Annotation> annotations, Class<?> annotationType) {
        if (annotations == null) {
            return null;
        }

        return getAnnotationByType(annotations.toArray(NO_ANNOTATIONS), annotationType);
    }

    public static Annotation getAnnotationByType(Annotation[] annotations, Class<?> annotationType) {

        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationType)) {
                return annotation;
            }
        }

        return null;
    }
}

Related

  1. getAnnotationAttributes(Annotation annotation)
  2. getAnnotationAttributes(Annotation annotation)
  3. getAnnotationAttributes(final Annotation annotation)
  4. getAnnotationAttributeValue(final Annotation annotation, final String attributeName)
  5. getAnnotationByType(AnnotatedElement element, Class annotationType)
  6. getAnnotationClass(Annotation a)
  7. getAnnotationClass(Annotation annotation)
  8. getAnnotationClass(Class clazz, Class annotation)
  9. getAnnotationClass(Class entityClass, Class annotationClass)