Solved

Java object reference from string

Posted on 2006-07-17
2
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
Simple Linear Regression

631 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