4 ms·
It's pass by value for primitives and pass by reference for objects. But it depends on what you call a reference. If all java objects would be immutable, you co
by DjDarkman 16y ago
It's pass by value for primitives and pass by reference for objects.
But it depends on what you call a reference. If all java objects would be immutable, you could say it's pure pass by value, but since you can alter the original object's state in the method, I call it pass by reference.
Before downvote: please explain, thank you.
- awj 16y ago...except that when methods are implemented a pointer to the "object" is what gets handed over. The narrow distinction that this pointer is passed by value makes some people feel exceedingly clever, despite the fact that the semantics of pass-by-reference in respect to the object itself are preserved.
- stonemetal 16y agoGet a metaphorical microscope and focus in on call semantics in Java. Arguments no matter what their type are pass by value. So then What are you allowed to pass as arguments to a function in java? Primitive types, it is impossible to pass an object to a function in Java. Then what actually happens when people claim they are passing an object to a function in Java? It is passing a primitive type of type object reference to the function. It is doing so by value.
- wlievens 16y agoYou're completely wrong, sorry. Pass by reference means you change the value of a variable passed from the caller's context. You can't do that in Java.