This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Getting local variable names and their data types in a java program

 
Amol Parikh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am writing a code which gets all the function names, function parameters , return type ,variable names as well as their data types using the reflection API. The problem I am facing is the information related to the variables is limited only to static class variables. I would also like to get the names and data types of the local variables inside different methods as well. If you guys could help me out with it. Thanks a lot...
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Report post to moderator
You don't get static variables only. You can also get instance variables using the clazz.getFields() method.
You however, cannot get local variables declared in methods using reflection. For that you'd need some debugging API and byte code manipulation languages like ASM.
You should try to find reasons not to have to do any of this.
 
Amol Parikh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
What do you mean when you say some debugging api?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Report post to moderator
Amol Parikh wrote:What do you mean when you say some debugging api?

http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/

Again, please do yourself a favor and find/invent reasons for not having to do this.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Report post to moderator
Repeatedly asking the same question is not going to get you a different answer.
First time
Second time
 
    Bookmark Topic Watch Topic
  • New Topic