This question already has an answer here:
It is possible to initialize the value of the field?
I am able to get the fields from the subclass from the superclass
Field[] fields = this.getClass().getDeclaredFields();
for(Field field : fields) {
//I need to assign a value to every field depending on their type
if(Integer.class.isAssignableFrom(field.getType())) {
//Something like this
field = (Integer) 100;
} else if(MyObject.class.isAssignableFrom(field.getType())) {
//Something like this
field = new MyObject();
}
}
Aucun commentaire:
Enregistrer un commentaire