flash
flash

Reputation: 1229

How does the Eclipse debugger gets the information about private variables inside the class?

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

Answers (2)

Donal Fellows
Donal Fellows

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

dube
dube

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

Related Questions