java - Dereferencing possible? -
consider following code:
public class test { static private volatile integer number1 = 42; static private volatile integer number2 = 42; public static void main(string[] args) { test test = new test(); test.changeinteger(number1); system.out.println(number1); } public void changeinteger (integer number) { number = new integer(3); } }
i change value of either number1
or number2
depending on argument pass method changeinteger
. doesn't work. there way make work in java without using reflection?
to clarify: want call changeinteger(number1)
change field number1
.
just add @margus's answer. in books, if variable name ever contains number, number1
, that's sign aren't doing right. use array.
on other hand, if variables named, may better of using hashtable
. names of fields in class meant hard-coded. if ever need non-hard-coded "field names", aren't fields. data! hashtable / dictionary correct route in java.
Comments
Post a Comment