Pass by value vs. Pass by reference June 23, 2005
Posted by javafoo in OOAD, java interview, javanotes.trackback
Always pass by value, if you ever say pass by reference, you will be rejected for sure. (in the interview that is)
You don’t believe me, this guy explains it far more better than I ever can.
Ok. There’s no question about java’s only semantics on functions is pass by value. But what about if you want to implement swap function with parameters (obj1, obj2) so how are you going to do it? Some says you should do it inline, I say it would be buggy if there’s so many swapping happening on the code. So I think java designers have at least provided a pass by reference even if it is just a convenience preprocessing such as inline functions on C++. Imagine a code with full of swapping lines with out a helper function to do it.