Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Repeatedly asking the same question is not going to get you a different answer.
First time
Second time
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic