I have the following
class Test{
public Inner x;
public static void main(String[] args){
Test t = new Test();
t.bar(t.x);
}
public Test(){
x = new Inner();
System.out.println("X = "+x.val);
}
public void bar(Inner a){
x.val = 2;
System.out.println("a = "+a.val);
a = new Inner(5);
System.out.println("a = "+a.val);
System.out.println("X = "+this.x.val);
}
class Inner{
public int val;
public Inner(){val=0;}
public Inner(int i){val=i;}
}
}
I am concerned why the program tells me that my class's inner object and passed-in object are the same, but when I change the passed object to a new one, they are suddenly not the same. I thought java passed by pointers, and thus changing the pointer location of "a" in my bar method would likewise change the pointer location of "x", which was passed in.