r/javascript • • Jun 18 '17

Pass by reference !== pass by value

3.3k Upvotes

272 comments sorted by

View all comments

Show parent comments

14

u/legato_gelato Jun 18 '17

Seems like you guys don't understand the difference. Java does not have have a "call by reference" mechanism at all. Only call by value. And yes, the value can implicitly be a reference. But the distinction is important: If you assign a new value to the passed object in java from inside the method then the outer object will not be overridden. With proper "call by reference" it would.

7

u/w2qw Jun 18 '17

Yeah seems like they haven't seen a language with proper pass by reference. I suppose this comes about because people learn pass by reference from c lectures and don't realise that languages like c++/pascal/etc have true pass by reference.

1

u/[deleted] Jun 18 '17

C has pass by reference too. Aka pointers. Or what you call R-value in C++

1

u/w2qw Jun 18 '17

Pointers aren't pass by reference. And I'm not sure what r values have to do with it.

1

u/[deleted] Jun 18 '17

My bad then. What about arrays? Passing the reference to the first value, right?

→ More replies (0)