Who modified my local variable?

Bryan Sant bryan.sant at gmail.com
Tue Jun 13 10:27:50 MDT 2006

On 6/13/06, Shane Hathaway <shane at hathawaymix.org> wrote:
> While I think your intended meaning is correct, I don't believe you're
> using the term "pass by value" correctly here.  I think the more correct
> thing to say is that Java passes primitives by value and objects by
> reference.


> You're saying Java passes references by value, but that's an unclear
> term that's hard to distinguish from the idea of passing pointers by
> value.  C passes pointers by value, which is equivalent to saying C
> passes pointers.  Unlike passing a reference, passing a simple pointer
> does not cause a new reference to appear in the object graph, and the
> unwary C/C++ programmer mixing references and pointers may get an object
> freed from memory prematurely.
> So again, I think a better way to express your point is to say that Java
> passes primitives by value and objects by reference.  Higher level
> languages like Python do away with primitives and pass everything by
> reference.

It's just a matter of terminology.  In Java, when I say:  Object o =
new Object();

What is "o"?  An object?  Nope.  It is an "object reference".  That
reference is always passed by value.

When coming from C/C++ this is harder to understand then just saying,
"Primitives are passed by value and objects are passed by reference".
A C guy gets that.  To anyone else, the simpler thing is to eliminate
the concept of value/pointer passing, and just adjust the terminology.

But your description is totally correct from a traditional terminology


More information about the PLUG mailing list