this was an interview question posed to me..I vaguely answered it uses Java reflections..but I was not sure. how does that work?
views:
114answers:
2
+6
A:
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.
dube
2010-05-04 09:36:55
+5
A:
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.
Donal Fellows
2010-05-04 09:40:19