News for hackers. Stuff that matters.
Re:Java is Pass-by-Value, Dammit by kelnos on Sunday March 22, 2015 @04:01AM (#9245998)
I think the confusion comes from one main place.

C has the address-of operator (&). So you can pass the address of a pointer, change what that points to in a function, and then the variable outside the function has indeed changed to point to a new chunk of memory. Java only has primitives and pointers to objects, and it only allows you to pass those by value to functions. You can't take the address of a primitive or object and pass that.

So basically in C you can pass an object (struct) or even primitive by reference... or at least you can fake it with trivial syntax. In Java you just cannot do that, and I think Java's use of the term "reference" to mean "pointer" makes some people (understandably) confused.

Re:Java is Pass-by-Value, Dammit by lucio on Sunday March 22, 2015 @09:50AM (#9246722)
>You can't take the address of a primitive or object and pass that.

Not correct.

In Java, if you have an object you take the address and pass it. If you have a primitive, you pass a copy of the value. Both things are called "pass-by-value" (something that confuses a lot of people).

Re:Java is Pass-by-Value, Dammit by jjnoakes on Sunday March 22, 2015 @11:00AM (#9246928)
Java has no notion of "taking the address of an object" because you never have an expression that refers to an object directly. You only have the addresses, so there's no need (or way) to convert objects to their address.

And it's all pass by value (for all values you could have - numbers, addresses, booleans, whatever).

Re:Java is Pass-by-Value, Dammit by kelnos on Wednesday March 25, 2015 @09:04PM (#9267166)
Heh, see why this is so confusing? That is of course what I meant -- it's really that Java, passing-wise, just has primitives and addresses to objects.