3 ms·
Sorry. But this just is not right. Pass-by-reference has a specific meaning, and by ignoring that, you are adding to the confusion and doing a disservice to ev
by jjnoakes 12y ago
Sorry. But this just is not right.
Pass-by-reference has a specific meaning, and by ignoring that, you are adding to the confusion and doing a disservice to everyone who genuinely wants to learn what is right. Stop doing that.
If you "x = new Foo()" inside a routine and it changes the value of y in "call(y)" then it is pass-by-reference. Period.
Java does not do this. Java is pass-by-value only.
Just because you can dereference your copy of a variable holding an object reference (or pointer - they are synonymous in the JLS) and mutate the pointed-to object, which the caller can then see through their copy of their pointer variable, does not mean you are passing by reference.
You are passing an object reference (pointer) by value.