File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Getting Information from Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting Information from Class" Watch "Getting Information from Class" New topic
Author

Getting Information from Class

Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Information from Class