Java passing by reference, where a good detailed explaination?
Hi,
I am new to the forum and I have a question for you. I am trying to properly understand the Java passing by reference but I am getting a little bit confused.
Does Java pass by reference or by value?
I have a quote from James Gosling stating as following:
Some people will say incorrectly that objects are passed “by reference.” In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory…. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode — pass by value — and that helps keep things simple.
On the other hand I am studying on Thinking in Java by Bruce Eckel where it is stated that Java - apart from primitives - pass objects by reference.
So where is the truth? Where can I find a detailed explaination?
Thank you and kind regards,
Giulio.