jeudi 25 décembre 2014

Reflection Field setValue for inner object


class User{
Account account;
String name;
}

class Account {
Integer amount;
}


**main :**
User u = new User();
Field field = u.getClass().getDeclaredField("account");
field.setAccessible(true);
Field amount = field.getType().getDeclaredField("amount");
amount.set(field, new Integer(1000));


console :



Exception in thread "main" java.lang.IllegalArgumentException: Can not set
java.math.BigDecimal field com.company.Account.amount to java.lang.reflect.Field


How to set value into Account.






Aucun commentaire:

Enregistrer un commentaire