You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by MUTHURAMAN SWAMINADHAN <mu...@yahoo.com> on 2009/11/02 22:49:42 UTC

Getting the local variables of a method

Hi,
 
I have been trying to get the local variables in a method but I don't see anything returned. I am using the following snippet.

LocalVariable lv[];
LocalVariableTable lvt;
lvt=mt.getLocalVariableTable(); //mt is a method  object
lv=lvt.getLocalVariableTable();
 
I don't get anything back in the lv array. Can anyone advise if this is the correct approach or if there is a better approach?

Thanks,
 Muthu
 
 
       
 
 
 
       


      

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Re: Getting the local variables of a method

Posted by Matthew Wilson <mj...@googlemail.com>.
2009/11/2 MUTHURAMAN SWAMINADHAN <mu...@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 following snippet.
>
> LocalVariable lv[];
> LocalVariableTable lvt;
> lvt=mt.getLocalVariableTable(); //mt is a method  object
> lv=lvt.getLocalVariableTable();
>
> I don't get anything back in the lv array. Can anyone advise if this is the correct approach or if there is a better approach?

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:

  http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#5956

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.

Kind regards,
Matthew

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org