Java Reflection Annotation getAnnotation(Annotation[] annotations, Class annotationClazz)

Here you can find the source of getAnnotation(Annotation[] annotations, Class annotationClazz)

Description

get Annotation

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <T extends Annotation> Optional<T> getAnnotation(Annotation[] annotations,
            Class<T> annotationClazz) 

Method Source Code

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

import java.lang.annotation.Annotation;

import java.util.Optional;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T extends Annotation> Optional<T> getAnnotation(Annotation[] annotations,
            Class<T> annotationClazz) {
        for (Annotation a : annotations) {
            if (annotationClazz.isAssignableFrom(a.getClass())) {
                return Optional.of((T) a);
            }/*from  w w w  . ja va  2s .  co m*/
        }
        return Optional.empty();
    }
}

Related

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