Java Reflection Annotation getAnnotationOfField(Field field, Class clazz)

Here you can find the source of getAnnotationOfField(Field field, Class clazz)

Description

get Annotation Of Field

License

Open Source License

Declaration

public static <T extends Annotation> T getAnnotationOfField(Field field, Class<T> clazz) 

Method Source Code


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

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

public class Main {

    public static <T extends Annotation> T getAnnotationOfField(Field field, Class<T> clazz) {
        for (Annotation annotation : field.getDeclaredAnnotations()) {
            if (annotation.annotationType() == clazz) {
                return clazz.cast(annotation);
            }//w w  w  . j  av  a  2s. c o m
        }

        return null;
    }
}

Related

  1. getAnnotationInstances(Class clazz, Class annotationClass)
  2. getAnnotationMemberDefaults(Annotation annotation)
  3. getAnnotationMemberType(Annotation annotation, String memberName)
  4. getAnnotationMetaAnnotated( AnnotatedElement annotatedElementClass, Class metaAnnotationToFind)
  5. getAnnotationMethods(Class annotationType)
  6. getAnnotationOuterIndecies(Class annotationClass, Annotation[][] annotations)
  7. getAnnotationPropertyValue(Annotation a, String annotationPropertyName)
  8. getAnnotationRecursive(Class cls, Class annotationClass)
  9. getAnnotations(AnnotatedElement ae, Class annotationType)