• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Information from Class

 
Pat Flickner
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get information out of a class and am looking to see if I can do it in a similar fashion that I do in JavaScript. In JavaScript, I can use the getElementById() method to pass a variable's name in and return the value of that variable. I have looked at several classes, the most recent Introspector, in the hopes that I can simply pass the variable's name in from a constant and have the process return me its method's value. To be exact, here's what I have:

Constant:


Processing Code:


I'm using a Hashtable to map the variable name to the corresponding method:


Is there a means of getting the values if I were to capitalize the first character and preface it with "get"? It would be so much simpler than typing in all that code. I've already done it for one program, but I would like to not EVER have to do that again (about 65 variables to code). I already have enough to do. Yes, I'm whining. Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34210
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use reflection to get the value directly. This is slower than regular code though. I'm not sure I understand the problem. Most IDEs let you generate the getters and setters so you don't have to type them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic