Java Reflection Annotation getAnnotation(Object obj, Class annotation)

Here you can find the source of getAnnotation(Object obj, Class annotation)

Description

get Annotation

License

Apache License

Declaration

public static <A extends Annotation> A getAnnotation(Object obj, Class<A> annotation) 

Method Source Code


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

import java.lang.annotation.Annotation;

import java.lang.reflect.Field;

import java.util.Objects;

public class Main {
    public static <A extends Annotation> A getAnnotation(Object obj, Class<A> annotation) {
        Objects.requireNonNull(obj);

        return obj.getClass().getDeclaredAnnotation(annotation);
    }/*from  ww  w .  java 2  s .c  o  m*/

    public static <A extends Annotation> A getAnnotation(Class<?> clazz, Class<A> annotation) {
        Objects.requireNonNull(clazz);
        Objects.requireNonNull(annotation);

        return clazz.getDeclaredAnnotation(annotation);
    }

    public static <A extends Annotation> A getAnnotation(Field field, Class<A> annotation) {
        Objects.requireNonNull(field);
        Objects.requireNonNull(annotation);

        return field.getDeclaredAnnotation(annotation);
    }
}

Related

  1. getAnnotation(Object bean, final Class annotation)
  2. getAnnotation(Object context, Class annotation)
  3. getAnnotation(Object instance, Class type)
  4. getAnnotation(Object obj, Class annClass)
  5. getAnnotation(Object obj, Class acl)
  6. getAnnotation(ProceedingJoinPoint pjp, Class annotationClass)
  7. getAnnotationAttribute(Annotation a, String attrName)
  8. getAnnotationAttribute(final Annotation anno, final String attrName, final Class attrType)
  9. getAnnotationAttributes(Annotation annotation)