posted 18 years ago
To be more precise, you do not actually pass an object into a method. nor do you pass a primitive.
with primitives, you pass a COPY of the VALUE. nothing that changes the value inside the method will effect the value outside the method.
With objects, it actually works the same way. That is becuase your variable does not hold an object, but a REFERENCE TO and object - effectively an address (or a pointer, for you C folk). you pass a COPY OF THE VALUE of the reference. if, inside the method, you change where the method's copy points to, you will not change what the outer reference refers to. it still points to the same old place.
however, if you use the inner reference to alter the object it refers to, then that will be reflected in what the outer reference points to (since it points to the same place).
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors