Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Constructor (Or Methods) Parameter Annotation Using Reflection

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.
        }   
    }
like image 721
ryandlf Avatar asked Mar 18 '26 15:03

ryandlf


1 Answers

constructor.getParameterAnnotations() returns the annotations for each parameter. For example, the annotations for the 2nd parameter are:

Annotation[] annotations = constructor.getParameterAnnotations()[1]
like image 166
Bozho Avatar answered Mar 21 '26 03:03

Bozho