wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Is it possible to build a String then use it as a variable name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is it possible to build a String then use it as a variable name?" Watch "Is it possible to build a String then use it as a variable name?" New topic
Author

Is it possible to build a String then use it as a variable name?

Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
I'm trying to avoid a ridiculous number of 'if's, and the only way I can think of to do so is to build the variable names of constants that are defined elsewhere in the API. Can anyone help?
Thanks,
g.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I don't understand your question exactly.
Could you elaborate on what you mean?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
I actually got it figured out. I did this:

Where DORF0324 is a static class.
Thanks anyway!
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
huh??? (scratching my head)


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

and you're using reflection just to reduce the amout of code you have to write
Um, have you tried profiling the amount of time to do each? In JDK1.2, method invokation using reflection took 200x longer than calling the method directly. And thats when you cache methods rather than looking them up each time.
It apparently got better in JDK1.3 and is now more like 20x as long, but is this really what you want when a second solution might be to format the code differently?
Karl Laird
Ranch Hand

Joined: Jul 14, 2001
Posts: 67
We might be able to help more if you post an example of the code you are trying to streamline.
Without, it is difficult to make intellegent suggestions - would a case statement be appropriate?
static final constants can often be used to provide mappings to more complex combinations circumventing the limitation of int / char cases.


The Eagle sneers at the Peacock<p>Systems Administrator<br />OrderWare Solutions Ltd<br /><a href="http://www.orderware.net" target="_blank" rel="nofollow">http://www.orderware.net</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to build a String then use it as a variable name?
 
Similar Threads
Dynamic properties
how to set the classpath
setTimeout problems.
JTextField - IllegalArgumentException - Too complicated
error : Cannot use classic compiler, as it is not available