Re: Getting the local variables of a method
Matthew Wilson <mj.wilson.uk <at> googlemail.com>
2009-11-03 09:32:07 GMT
2009/11/2 MUTHURAMAN SWAMINADHAN <muthu437 <at> yahoo.com>:
> I have been trying to get the local variables in a method but I don't see anything returned. I am using the
> LocalVariable lv;
> LocalVariableTable lvt;
> lvt=mt.getLocalVariableTable(); //mt is a method object
> I don't get anything back in the lv array. Can anyone advise if this is the correct approach or if there is a
The local variable table is an optional table in the class file.
Unless you compile with the debug option (which, by default, includes
the local variables, line numbers, and location of the original
source), it will be missing. Try "javac -g" to compile.
See the Java VM specification for more details:
You can also use javap to have a look at the local variable table (to
see if it is there in the file):
javap -verbose MyClass
I hope that helps.