Java Reflection Annotation Find findAnnotationFromClass(Class target, Class annotation)

Here you can find the source of findAnnotationFromClass(Class target, Class annotation)

Description

find Annotation From Class

License

Open Source License

Declaration

public static Annotation findAnnotationFromClass(Class<?> target,
            Class<? extends Annotation> annotation) 

Method Source Code

//package com.java2s;
/*//from   ww  w  .  j av a  2s  . c o m
 * Copyright (c) 2016, Quancheng-ec.com All right reserved. This software is the
 * confidential and proprietary information of Quancheng-ec.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Quancheng-ec.com.
 */

import java.lang.annotation.Annotation;

public class Main {
    public static Annotation findAnnotationFromClass(Class<?> target,
            Class<? extends Annotation> annotation) {
        for (Annotation targetAnnotation : target.getAnnotations()) {
            if (annotation.isAssignableFrom(targetAnnotation
                    .annotationType())) {
                return targetAnnotation;
            } else {
                continue;
            }
        }
        return null;
    }
}

Related

  1. findAnnotation(Set annotations, Class annotationClass)
  2. findAnnotationClass( Class c, Class base)
  3. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  4. findAnnotationDeclaringClass(Class annotationType, Class classToFind)
  5. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  6. findAnnotationFromMethodOrClass(final Method method, final Class annotationClass)
  7. findAnnotationHelper( Class base, Type iface)
  8. findAnnotationIn(List modifiers, Class clazz)
  9. findAnnotationInAnnotations(AnnotatedElement annotatedElement, Class annotationClass)