I need to know the type of the local variables. I am using Java reflection, using which I could not get it. Can you please let me know how to know the type/name of the local variables.
Can I get information about the local variables using Java reflection?
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
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.
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