Re:Incorrect Core Java Interview Answers
by JoeAltmaier on Sunday July 31, 2011 @08:55AM
(#2828224)
I believe any object passed in Java can be modifed by the receiving method, right? So that is pass-by-reference. If we want to say we're really passing a reference by value, that begins to be silly - if the object passed can be modified, its a reference.
There is a simple way to check whether a language does call-by-reference: can you write a swap function such that after calling swap(a, b), the variables a and b in the calling function refer to different values than before? In Java this is impossible.
Because the terminology is so confusing when object reference values are being passed-by-value, Barbara Liskov suggested we call it call-by-sharing.
[1] you can make C look like it's doing pass-by-reference by throwing some & and * operators around. That doesn't change the fact that it is purely call-by-value.