繁体   English   中英

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

[英]Get Constructor (Or Methods) Parameter Annotation Using Reflection

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

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.
        }   
    }

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

Annotation[] annotations = constructor.getParameterAnnotations()[1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM