Here is what is happening:
int[] copyFrom = {1,2,3,4,5,6,7,8,9};
int[] copyTo = new int[9];
can be visualized as
copyFrom ------------> [1,2,3,4,5,6,7,8,9]
copyTo ------------> [0,0,0,0,0,0,0,0,0]
Now copyTo = copyFrom;
makes copyTo
hold same value as copyFrom
so new situation looks like
copyFrom ---------+
|
+--> [1,2,3,4,5,6,7,8,9]
|
copyTo ---------+
As you see there are still two references, but they just hold same value so changing one of them can't affect other (I am talking about changing value of references - ref = new Value();
- not state of object they hold ref.setParam(foo);
)
Then you change copyFrom
reference to hold new array copyFrom = new int[9];
so now you have
copyFrom ------------> [0,0,0,0,0,0,0,0,0]
copyTo ------------> [1,2,3,4,5,6,7,8,9]
That is why System.out.println(copyTo[0]);
prints 1
.