Let's say you have a class: SomeClass with fields a=10, b=20, and c=30, where instanceOfSomeClass.getA()==10. I want a map like this
{
a:10
b:20
c:30
}
I tried this, but got Class can not access a member of class with modifiers "private static final", but I also can't modify this class to not have private static final:
Field[] fields = SomeClass.class.getDeclaredFields();
for (Field f : fields) {
map.put(f.toString(), f.get(instanceOfSomeClass).toString());
}
Any ideas on how to make this hashmap?
Aucun commentaire:
Enregistrer un commentaire