Obtendo todos os atributos de um objeto

From Basef
Revision as of 23:29, 9 July 2017 by Admin (Talk | contribs) (Criou página com 'Para obter todos os atributos de um objeto 'o': <source lang="java"> try { Class<?> c = o.getClass(); for (Field f: c.getFields()) { Object value = f.get(o);...')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Para obter todos os atributos de um objeto 'o':

try {
    Class<?> c = o.getClass();
    for (Field f: c.getFields()) {
        Object value = f.get(o);
 
        if (value == null) {
            System.out.println(f.getName());
        }
    }
} catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException();
}