is it possible to read private fields using Java reflection?
Asked
Active
Viewed 801 times
-2
-
1Thanks @BahramdunAdil, can please help me how it goes? – Amol Patil Dec 17 '15 at 07:12
-
1Can you try little google or search on SO itself. – YoungHobbit Dec 17 '15 at 07:12
-
Yes, look at it [here](http://stackoverflow.com/a/11282279/1196295). – BhushanK Dec 17 '15 at 07:13
1 Answers
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
- 168,305
- 31
- 280
- 331