Using reflection in this case would be redundant. You can get the expected behavior simply using Map :
Map<String, Integer> variables = new HashMap<String, Integer>();
Then the keys to the map will be the names of the variables, and the values are real values:
variables.put("var1", 10); variables.put("var2", 20);
You will later get values similar to this:
Integer n1 = variables.get("var1"); // n1 == 10 Integer n2 = variables.get("var2"); // n2 == 20
And if you need to update the values:
variables.put("var1", variables.get("var1") + 32); Integer n3 = variables.get("var1");
source share