i added some print statements to the method change_i like this:
public static void change_i(String i[])
{
String j[] = {"Method"};
i = j;
System.out.println("i.toString() = " + i.toString() );
System.out.println("j.toString() = " + j.toString() );
System.out.println("method: j[0] = " + j[0]);
System.out.println("method: i[0] = " + i[0]);
}
here is the result:
i.toString() = [Ljava.lang.String;@7e74a5e3
j.toString() = [Ljava.lang.String;@7e74a5e3
method: j[0] = Method
method: i[0] = Method
class: i[0] = hi original
so based on these results here is what i see going on:
- method "change_i" gets a copy of the reference that is contained in "i"
- "i" is then assigned the reference to j, but only in the method "change_i".
- the original reference that "i" contains in "main" is unchanged
[This message has been edited by keith barron (edited April 06, 2001).]
[This message has been edited by keith barron (edited April 06, 2001).]