mardi 25 juin 2019

How do I convert the string to the setter function, if the method takes a primitive type?

I am trying to generate a setter for a class which takes a parameter of primitive type, but I am getting an exception since only non-primitives are allowed.

For this I am taking a string and converting it exactly the way the function is in my POJO, but while describing the type of the parameter (int) it's taking its wrapper class (Integer).

Method method = resultClass.getClass().getMethod(getSetMethod(key), value.getClass());


private String getSetMethod(String key) {
    key = key.substring(0, 1).toUpperCase() + key.substring(1);
    key = "set"+key;
    return key;
}

Can anyone tell me if there is an alternative way to generate this method which works for both the primitive and non-primitive types?





Aucun commentaire:

Enregistrer un commentaire