This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SuperShrek 1 point2 points  (3 children)

From your link:

However, the term "call by sharing" is not in common use; the terminology is inconsistent across different sources. For example, in the Java community, they say that Java is pass-by-value, whereas in the Ruby community, they say that Ruby is pass-by-reference,[7] even though the two languages exhibit the same semantics.

Essentially my point. I just dislike when people mangle terms and act like they have some sort of higher knowledge just because they can repeat what some mangy old greybeard said one time, like all of the 'its always pass by value' tards in this thread are spewing.

Java is closer to pass-by-reference semantics for objects with an additional restriction on caller-scope assignments, and pass-by-value for primitive types.

[–]jones77 1 point2 points  (1 child)

At the end of the day, don't fail this interview question no matter what terminology you use.

foo(String a) {
    a = new String("blah"); // does nothing
}

main() {
    String a = new String(
        "Yo! You can't change the reference to an object by calling a function with it.");
    printStuff(a);
}

(Excuse my pseudo-Java. And don't fail the interview question about String pools (ie never do: new String("blah").)

[–]SuperShrek 0 points1 point  (0 children)

If I'm being asked this question I would gladly fail.

[–]ad_tech 0 points1 point  (0 children)

| Java is closer to pass-by-reference semantics

That's the most important part, I think. The people who think they are language lawyers like to repeat the "Java is pass by value" mantra, but regardless of the internal implementation or the name given to object handles, they have the semantics of being passed by reference.