使用Reflection获取构造函数(或方法)参数注释

rya*_*dlf 3 java reflection constructor annotations

如何从构造函数参数中的参数获取注释.我试过了...

Class<?>[] params = constructor.getParameterTypes();
    if(params.length > 0) {
        paramValues = new Object[params.length];
        for(int i=0; i<params.length; i++) {                        
        Annotation[] constructorAnnotations = params[i].getAnnotations(); //This does not work.
        }   
    }
Run Code Online (Sandbox Code Playgroud)

Boz*_*zho 7

constructor.getParameterAnnotations()返回每个参数的注释.例如,第二个参数的注释是:

Annotation[] annotations = constructor.getParameterAnnotations()[1]
Run Code Online (Sandbox Code Playgroud)