How do I obtain the annotation from a parameter within the constructor arguments. I have tried...
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()
returns the annotations for each parameter. For example, the annotations for the 2nd parameter are:
Annotation[] annotations = constructor.getParameterAnnotations()[1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.