Hi Greg,
perhaps I should have used objects to avoid confusion. Works the same:
prints
java.awt.Point[x=1,y=1]
java.awt.Point[x=1,y=1]
The method, step by step:
static void method(Point parameter) { a copy of the reference (i.e. a copy of the byte
pattern telling where the object can be found) is passed to the method.
As the methods is called from main with (a), parameter points to the point object [1,1].
Point local = parameter; A new reference (I called it local now) is created. It points to the object where parameter points to. Same [1,1].
If "parameter" would be redirected (or re-referenced as these Java Gurus call it) to some other object, "local" would still point to [1,1].
parameter = b; The parameter (not a!) is redirected to the object that b points to, the [2,2] object.
b = local; Here's the knack. The class variable b, that originally pointed to [2,2] is now redirected to the object local points to, i.e. the [1,1] object. It will still point to [1,1] even if the method is over and local will be GC-ed.
By the way, the middle part is unnecessary, here's the original again:
Is just the same as
meaning "static variable i2 is where parameter points to.".
And this is the i1 (class variable) from the call in main.
Yours,
Bu.
[ December 05, 2006: Message edited by: Burkhard Hassel ]