3 ms·
It's not. In java the object's reference is passed by value. There is a difference between passing an object by reference and passing the reference of the obje
by Monkeyget 16y ago
It's not. In java the object's reference is passed by value.
There is a difference between passing an object by reference and passing the reference of the object by value.
In the first case caller and callee share the same pointer to the same object while in the latter case each have a different pointer to the same object.
This article explains it very well : http://javadude.com/articles/passbyvalue.htm http://javadude.com/articles/passbyvalue.htm
- NickPollard 16y agoSurely then, passing an object by reference is just passing the reference to the reference to the object by value? It's references all the way down! To take it to a lower level, we're passing a string of binary digits to the function. This happens either through a register, or through the stack. The function then has to decide what to do with it - either it uses it as the value of something, or it takes it as a memory address and derefences it. It can then repeat this last step for as many levels of indirection as it wishes. It's clearer in C. void f(struct object a); // Pass struct by value void f_(struct object* a); // Pass struct by reference, pass reference by value void f__(struct object a); // Pass reference to struct by reference, pass reference to reference to struct by value void f________struct object a); // What the hell are you doing? You've created a monstrosity