Assuming that you are talking about a method or constructor's local variables, you cannot find out about them using reflection. You have to either
- use a bytecode library such as BCEL or ASM, or
- use one of the remote debugger APIs.
The latter will allow you to access the values of the local variables, but only while the JVM is suspended by the debug agent.
Both of these approaches rely on the classes in question being compiled with debug information. Specifically, the classes need to be compiled with "local variable debugging information"; e.g. using javac -g ...
. The "vars" debug information is not included by default.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…