samedi 1 septembre 2018

Return

I am trying to use reflections to decide on runtime which method needs to be called. I have used the below piece of code to implement the same:

 if(tempVar instanceof String)    
getterMethod1 = genericDTO.getClass().getMethod("set" + field.substring(0, 1).toUpperCase() + field.substring(1), String.class);

The decision is made based on tempVar. I wanted to be able to return String.class directly from tempVar so that I can avoid multiple if-else-if blocks. Right now tempVar.getClass() returns only String. Is there a method that outputs something like String.class instead of simply String.





Aucun commentaire:

Enregistrer un commentaire