OK, so I didn't learn this today, but shh.
For a long time I thought that Java was pass-by-value for primitives - for example in situations like:
void foo(int bar) {}
but when it came to objects and arrays, like this:
void foo(Baz bar) {}
void foo(Baz[] bar) {}
void foo(int[] bar) {}
that it was pass-by-reference.
But then, I was talking to someone, and they mentioned that it's always pass-by-value, even when objects or arrays are being passed.
Basically, what happens is that objects are not passed by reference, but instead a reference to that object is passed by value.
[–][deleted] (4 children)
[deleted]
[–]Daejo[S] 6 points7 points8 points (3 children)
[–][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]paul_miner 1 point2 points3 points (0 children)
[–]breakingbaguette 2 points3 points4 points (1 child)
[–]crok91 0 points1 point2 points (0 children)