Obtendo todos os atributos de um objeto

From Basef
Revision as of 23:29, 9 July 2017 by Admin (Talk | contribs)

(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()) {
        System.out.println(f.getName());
    }
} catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException();
}