如何从构造函数参数中的参数获取注释。我试过......
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.
}
}
答案 0 :(得分:7)
constructor.getParameterAnnotations()
返回每个参数的注释。例如,第二个参数的注释是:
Annotation[] annotations = constructor.getParameterAnnotations()[1]