Java Reflection Annotation getAnnotation(Annotation[] annotaions, Class T)

Here you can find the source of getAnnotation(Annotation[] annotaions, Class T)

Description

find an annotation from an array

License

Apache License

Parameter

Parameter Description
T a parameter
annotaions a parameter

Declaration

@SuppressWarnings("unchecked")
public static <T> T getAnnotation(Annotation[] annotaions, Class<? extends Annotation> T) 

Method Source Code


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

import java.lang.annotation.Annotation;

public class Main {
    /**//from w w w.j  a v  a  2  s  .co m
     * find an annotation from an array
     * 
     * @param <T>
     * @param annotaions
     * @param T
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> T getAnnotation(Annotation[] annotaions, Class<? extends Annotation> T) {

        for (int i = 0; i < annotaions.length; i++) {
            if (annotaions[i].annotationType().equals(T)) {
                return (T) annotaions[i];
            }
        }

        return null;
    }
}

Related

  1. getAnnotation(AnnotatedElement aobj, Class aClass)
  2. getAnnotation(AnnotatedElement element, Class annotation)
  3. getAnnotation(AnnotatedElement element, String annotationTypeName)
  4. getAnnotation(AnnotatedElement target, String annotationType)
  5. getAnnotation(Annotation ann, Class annotationType)
  6. getAnnotation(Annotation[] annotations, Class annotationType)
  7. getAnnotation(Annotation[] annotations, Class annotationClazz)
  8. getAnnotation(Annotation[] annotations, Class annotationType)
  9. getAnnotation(Annotation[] annotations, Class clazz)