Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java object reference from string

Posted on 2006-07-17
2
Medium Priority
?
277 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
Loops Section Overview

772 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