lundi 18 mars 2019

how to create an object from Field.getType() reflection?

I create an reflection function to create a new object and set data inside.

This is my code but, i dont know how to fill object declaration class type:

<Class-Type> newObj = f.getType().getConstructor(new Class[]{}).newInstance();

f is a java.lang.reflect.Field that i get from class.getDeclaredFields()

i already try using Object type

Object newObj = f.getType().getConstructor(new Class[]{}).newInstance();

but after i invoke data

Method setterNewObj =newObj.getClass().getDeclaredMethod("set" + Character.toUpperCase(m.getName().charAt(0))+ m.getName().substring(1), m.getType()); setterNewObj.invoke(newObj, this.typeConvert(mapOfValue.get(nameOfColumn), m.getType()));

and i print.out the result data is not set (null);

Thanks





Aucun commentaire:

Enregistrer un commentaire