Java Reflection Annotation getAnnotationAttribute(Annotation a, String attrName)

Here you can find the source of getAnnotationAttribute(Annotation a, String attrName)

Description

Returns attribute value of given annotation with attrName attribute name.

License

Open Source License

Declaration

public static Object getAnnotationAttribute(Annotation a, String attrName) 

Method Source Code


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

import java.lang.annotation.Annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    /**/*  w ww  .  j  av  a 2s .c  o m*/
     * Returns attribute value of given annotation with <code>attrName</code> attribute name.
     */
    public static Object getAnnotationAttribute(Annotation a, String attrName) {
        try {
            Method method = a.annotationType().getMethod(attrName);
            return method.invoke(a);
        } catch (NoSuchMethodException e) {
            throw new AssertionError(e);
        } catch (SecurityException e) {
            throw new AssertionError(e);
        } catch (IllegalAccessException e) {
            throw new AssertionError(e);
        } catch (IllegalArgumentException e) {
            throw new AssertionError(e);
        } catch (InvocationTargetException e) {
            throw new AssertionError(e);
        }
    }
}

Related

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