Who modified my local variable?

Shane Hathaway shane at hathawaymix.org
Tue Jun 13 11:06:47 MDT 2006


dave at thesmithfam.org wrote:
> It's this kind of confusion that has prompted me to start using the term
> "Pass by Java." The fact is, though, that *everything* in Java is passed
> by value. You just have to know that all java.lang.Object derived
> objects are created with "new" and thus are pointers. So, when you pass
> an Object, Java is passing its pointer by value. This is absolutely NOT
> pass by reference, since you cannot reassign the original object's
> pointer by modifying it inside the method. This means that Java actually
> does not support pass by reference at all, not with primitives and not
> with java.lang.Object derived objects either. It only supports pass by
> value. It just happens that some values are pointers. Fun, eh? This is
> why I prefer C++ where I have total freedom to do "Pass by Java", pass
> by reference, or even Objects passed by value (Java can't do either of
> the latter two).

Interesting.  To me, the distinction between a pointer and a reference
is that a reference not only points to the object referenced but also
has some kind of strong link back to the thing that's referencing it.
That strong link backward is what makes garbage collection possible.  In
the C++ code "int foo(int &bar)", the variable bar is just a cleverly
disguised pointer, not a reference in the usage I am accustomed to.

I wonder which sense is standard?  Is the meaning of "reference"
different depending on the language?  Ugh, I hope not, but I bet it is.

Shane




More information about the PLUG mailing list