3 ms·
I'm not really sure what point you are trying to make here. In general, the whole thing about passing a reference by value is just BS. What you need to ask is
by agricola 12y ago
I'm not really sure what point you are trying to make here.
In general, the whole thing about passing a reference by value is just BS. What you need to ask is, "What am I passing to the function?"
If you are passing an object, and Java (or whatever language you are using) determines a reference (memory address or whatever), then passes that reference to the function, then you are, by definition, passing an object by reference. The important thing to focus on in this argument is, "What am I passing?" The answer for this scenario is that the programmer is trying to pass the object itself. Who cares about the address / location of the object.
If you decide to pass the reference explicitly, then you are passing a reference, not the object. This would be like explicitly passing a pointer in c++, and is apparently a controversial topic when it comes to Java. A reference will nearly always (I can't actually think of a case where it isn't) be a primitive, and therefore, be passed by value.
For argument sake, say I'm wrong about all this. My question would be, "What would it look like to pass an object by reference, and how does that differ from what is currently happening?"
- viraptor 12y agoThe point was, that there is a language close to java which can pass objects by value or by reference. (It passes object references by value or by reference if you want to call it like that) To pass an object by reference, it looks exactly like C#'s out/ref parameter. void function(ref SomeClass arg) { arg=null; } var a=new SomeClass(); function(a); // now a is null Which is different from what happens without ref. (or by default in Java)