This content has been marked as final. Show 4 replies
I don't get it. This has been asked a million times and the answer is always the same - any google about the subject will point to endless forum posts saying exactly the same. There is no need to question it anymore at this point in time. So why does it persist anyway? Which evil source is casting doubts into people's minds?
Welcome to the forum!
Is Java Support pass by reference or not?
No - see my detailed reply in thise thread
Java passing by reference, where a good detailed explaination?
That reply includes quotes from the Java Language Specification as well as links to articles that provide examples. This is from the spec
See section 8.4.1
Note that the above applies to argument expressions of ALL types: primitive or object. The value of the 'newly created parameter variable' is a COPY (by value) of the actual argument expression.
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.
So a method that has an object parameter can use the 'copy' of the object reference to manipulate the object the method can NOT change the reference to refer to a different object.