get Annotation Value - Android java.lang.reflect

Android examples for java.lang.reflect:Annotation

Description

get Annotation Value

Demo Code


//package com.java2s;
import java.lang.annotation.Annotation;

public class Main {
    public static final String VALUE_NAME = "value";

    public static Object getAnnotationValue(Annotation annotation) {
        return getAnnotationValueWithName(annotation, VALUE_NAME);
    }/*w w w.j  a  v  a2  s. c  om*/

    public static Object getAnnotationValueWithName(Annotation annotation,
            String valueName) {
        try {
            return annotation.annotationType().getMethod(valueName)
                    .invoke(annotation);
        } catch (Exception e) {
            return null;
        }
    }
}

Related Tutorials