For the debugging purposes I need to change the value of the private field. I use Eclipse for debugging, and I am able to change variables during debug process, but I have no access to the private variables. I tried to use a reflection in a change value view to set the field as "accessible" manually, but it looks like it doesn`t work. Do you know any IDE/framework/plugin or something that could allow it?
In Eclipse you can go to variable view which lists all your variables.
Here you can right click on the member variable which you want to change and select change value option, which pops up a separate window to change the value. which will take into effect from then onwards.
Yuo can use reflection to set field value (Spring provides convenient ReflectionTestUtil):
Class<?> c = foo.getClass();
Field field = c.getDeclaredField("valid");
field.setAccessible(true);
field.set(valid, Boolean.FALSE);
Also you shouldn't have any problems with setting private field's value in the debugger, it doesn't actually matter if it is private or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With