3 ms·
There isn't any semantic ambiguity. The phrase "pass by reference" has a specific meaning. Java does not support pass by reference. Here's a quick test to se
by panic 16y ago
There isn't any semantic ambiguity. The phrase "pass by reference" has a specific meaning. Java does not support pass by reference. Here's a quick test to see if your language uses pass by reference (when translated into Java, it will output "pass by value"):
function f(x, y) { x = y }
a = new A()
b = new A()
assert(a != b)
f(a, b)
if (a == b) {
print('pass by reference')
} else {
print('pass by value')
}
- randrews 16y agoYes, you're right, but the argument is still about semantics. Java programmers don't think in terms of passing a reference, they think in terms of passing an object (which happens to be done by passing a reference to it). There's a correct answer to airplane-on-a-treadmill too, but that doesn't mean it's not an argument about semantics. Please let's just stop this here before this thread becomes like that other thread.
- nopassrecover 16y agoAssumes equivalence is referential equivalence, and not overwritten. Of note, in some languages where there are immutable strings (e.g. java I believe) there is only "one true string" for each string (of course this isn't directly relevant to the example code given above). This means "var a = "test"; var b ="test"; assert(a==b);" holds true for referential equality.
- fleitz 16y agoWhich depends highly on the semantics of the == and = operators. So if in java you decided to create an assign method (cuz remember operators are evil in java) and overrode equals then you could create such a situation in which it would return pass by reference. Plus the equals operator in java is kind of f'ed anyways as it is. Conversely if the language was pass by value (or not retarded) then code such as this should work. function f(x, y) { x == y } a = new String("foo"); b = new String("f").append("oo"); assert(a != b) if (f(a, b)) { print('pass by value') } else { print('pass by reference') }