-2

is it possible to read private fields using Java reflection?

Amol Patil
  • 955
  • 2
  • 10
  • 40

1 Answers1

1

You can use the Apcache commons FieldUtils

FieldUtils.readField(object, myfield, true);

or else you can use the Reflection as is described and answered in the linked duplicate. So you can set the setAccessible(true) before invoking your method.

m = object.getClass().getDeclaredMethod(mymethod);
m.setAccessible(true);
m.invoke(object);
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319