Solved

Java object reference from string

Posted on 2006-07-17
2
260 Views
Last Modified: 2010-04-17
In some languages you can use a string as an object reference.

For example, in ActionScript:

var foo = "bar";
_global[foo] = "baz";

Is the same as saying

_global.bar = "baz";

Is this possible in Java, and if so what's the syntax?

Thanks,
Matt.
0
Comment
Question by:mb2297
2 Comments
 
LVL 15

Accepted Solution

by:
bpmurray earned 50 total points
ID: 17124319
No, you can't do that. I think you're looking for something to manage name-value pairs, where you want to grab the value associated with a name. In the example above, the name is "bar" and the value is "baz". If that's the case, you can use java.util.map:

    String myKey = "bar";
    String myValue = "baz";
    myMap.put(myKey, myValue);


    String val = (String) myMap.get(myKey);
0
 

Author Comment

by:mb2297
ID: 17124389
Using a Map was my backup plan. Thanks bpmurray
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
commonTwo  challenge 63 99
Exe program is not a valid Win 32 application 15 95
noX challenge 17 76
Scripting vs. Programming languages 25 115
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now