On Sat, 21 Oct 2000, Peter Schuller wrote:

> > Java doesn't pass by reference.  You can pass an object, and through that
> > access and change the fields it contains.
> 
> Java *does* pass by reference. All objects are passed by reference; primites
> are passed by value.

Not quite.

From the Java Language Specification, somewhere around:
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#38698

   When the method or constructor is invoked (§15.12), the values of the
   actual argument expressions initialize newly created parameter
   variables, each of the declared Type, before execution of the body of
   the method or constructor. The Identifier that appears in the
   DeclaratorId may be used as a simple name in the body of the method or
   constructor to refer to the formal parameter.

The "value" of an object could be thought of as a pointer to that object.
You aren't getting the pointer's address, you're getting it's value.  
It happens to point to the object you want.

Any changes made to the parameters themselves within the called method
are NOT passed back to the caller.  If I create a new object Foo and 
assign that to a parameter, the caller doesn't receive Foo back.

It's a matter of semantics.  
-- 
Joi Ellis                    Software Engineer
Aravox Technologies          [EMAIL PROTECTED], [EMAIL PROTECTED]

No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried.  Anything
that kicks a monopoly in the pants has got to be good for something.
           - Chris Johnson


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to