get Annotation Parameters - Java java.lang.annotation

Java examples for java.lang.annotation:Annotation Parameter

Description

get Annotation Parameters

Demo Code


import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Main{
    public static Map<String, Object> getAnnotationParameters(
            Annotation annotation) {
        Map<String, Object> parameters = new HashMap<String, Object>();
        for (Method m : ReflectionUtil.getAllMethods(
                annotation.annotationType(),
                ReflectionUtil.withParametersCount(0))) {
            try {
                m.setAccessible(true);/*  ww  w .j  av  a  2s. c  o  m*/
                parameters.put(m.getName(), m.invoke(annotation));
            } catch (Exception e) {
                // ignore
            }
        }
        return parameters;
    }
}

Related Tutorials