mercredi 31 mai 2017

How to grant access on all private fields values retrieved by reflection?

Is it possible to get a fields' value, without using field.setAccessible(true);?

 Field field = object.getClass().getDeclaredField(fieldName);    
 field.setAccessible(true);
 Object value = field.get(object);

I mean, could I simply grant access to all private fields of a specific class, without having to invoke the setter on each read?





Aucun commentaire:

Enregistrer un commentaire