From: James Gosling
Date: 1/13/11
Don Hopkins wrote:
>Hey I know it's 2011 and we're living in the future and all that, but
>there still seems to be some confusion and debate about a matter I
>thought was perfectly clear: Is Java pass by value or pass by
>reference?
Depends on your terminology. But it's kinda both. It's pass-by-value for
everything, with the twist that for class instances, the thing that's
passed-by-value is the pointer to the object, so it behaves like
pass-by-reference.
From: Don Hopkins
Date: 1/13/11
Reminds me of the controversy about Niklaus Wirth's name:
"Whereas Europeans generally pronounce his name the right way
('Nick-louse Veert'), Americans invariably mangle it into 'Nickel's
Worth.' This is to say that Europeans call him by name, but Americans
call him by value." - Introduction by Adriaan van Wijngaarden at the
IFIP Congress (1965).
It seems to be a consequence of pretending pointers don't exist -- you
also have to pretend you have variables with object values and
references, but you still can't write a swap(a, b) function. If you
think of Java object values as pointers, then it's obviously passing
references by value. But if you don't believe in pointers and think of
variables as containing objects, then it's obviously passing objects
by reference, but your view of the world is an illusion, because it's
really implemented with pointers.
Or is it??? Someone suggested a Magic Elves theory, which helps a lot
of other stuff to make more sense.
Here's the discussion from 2011 about this issue that prompted me to ask James Gosling for a clarification. You can see that many people were VERY confused, and extremely fanatical about maintaining and spreading their confusion, in spite of the fact that it directly contradicted the Java spec and the inventor of Java himself.Java is PASS BY VALUE.
http://www.theserverside.com/discussions/thread.tss?thread_i...