jeudi 4 février 2016

java reflection get field of the nested objects

I need to set a value to the field of the nested object.

For example I have the following example (please note that this is just simplified version of what I have in my real project)

public class Account {

    private Email email;

}

public class Email {

    private String personal;
    private String business;

}

So, what if I have an object of type Account account and I need to set personal email.

Field[] fields = account.getClass().getDeclaredFields();

This will return me an array containing only field - email. How can I reach to personal field of that email object?





Aucun commentaire:

Enregistrer un commentaire