Reputation: 1229
this was an interview question posed to me..I vaguely answered it uses Java reflections..but I was not sure. how does that work?
Upvotes: 6
Views: 848
Reputation: 137567
The key to your question is almost certainly java.lang.reflect.AccessibleObject
, which allows the debugger to turn off the access control checks and poke around. Spring uses the same mechanism to get access to the variables for dependency injection.
Upvotes: 9
Reputation: 5019
It uses the Java Debugger which provides commands to do just that:
jdb print myObj.myInstanceField
Back in the old days there were really people doing this on a command line! :)
NOTE: To display local variables, the containing class must have been compiled with the javac -g option.
Upvotes: 7