我知道,與以下,參考了Java - 引用原始數據類型?
public class MyClass
{
public Integer value;
}
public class Main
{
public static void main(String[] args)
{
MyClass john = new MyClass();
john.value = 10;
MyClass bob = john;
bob.value = 20;
System.out.println(Integer.toString(john.value)); // Should print value of "20"
}
}
但你如何做基本數據類型相似的參考?
public class Main
{
public static void main(String[] args)
{
Integer x = 30;
Integer y = x;
y = 40;
System.out.println(Integer.toString(x)); // Prints "30". I want it to print "40"
}
}
相關:http://stackoverflow.com/questions/40480/is-java-pass-by-reference – BalusC