Possible Duplicate:
Is Java pass-by-reference?
Java pass by reference
For the following Java program, my understanding is that a
is a reference type to an Integer, like pointer type in C/C++. So any changes done in method f
to its value will be reflected after the method returns. But println
still prints its original value 0
instead of 3.
Integer
and int
does not make a difference. Was my previous understanding wrong? Please help. Thank you!
public static void f(Integer b){
b=3;
}
public static void main(String[] args){
Integer a=0;
f(a);
System.out.println(a);
}