Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a Reference by String in Java [duplicate]

Is there any way to implement this sort of code in Java?

int foo = 3;
String data = "foo";
System.out.println(StringToReference(data));

and print 3?

Edit: Specifically, I'd like to parse a String or char and return an int representing a KeyEvent. For example, I'd like to be able to do this:

for(char c : "hello")
    new Robot().keyPress(StringToReference("KeyEvent.VK_"+c));
like image 208
Jared Nielsen Avatar asked Jan 14 '23 07:01

Jared Nielsen


1 Answers

Without knowing exactly what you are trying to accomplish, this is the closest I think you could get:

Map<String, Integer> map = new HashMap<String, Integer>();

map.put("foo", 3);

System.out.println(map.get("foo"));
like image 156
Sean Bright Avatar answered Jan 23 '23 17:01

Sean Bright