?
Solved

Java object reference from string

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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…
Six Sigma Control Plans

719 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