Quote Originally Posted by Chris256
All objects are passed by reference.
mmmh, kind of.. a new pointer is attached to the object and made available to the called method. what actually gets passed is a value of a pointer that is a reference to the object.

This is a weakness in java
you ought to have written "In my antiquated opinion, this is a weakness in java"

of course, my opinion that your opinion is antiquated, is just my opinion..

Code:
int main()
{
     Asdf a = new Asdf();
     function1(a);
}

void function1(Asdf b)
{
     b = new Asdf();
}
yes, but we dont do things like that any more. If you loaned your mp3 player to a friend to put some tunes on, would you expect him to give you back a whole new ipod, with the tunes on? what if your mum bought you your ipod and you were really sentimentally attached to it? you'd be upset..
what if what he gave you back wasnt even an ipod but some low spec $30 mp3 player?

this was how we did things one upon a time, but now we have more secure ways of programming.. we dont give object A to object B for object B to fiddle with as it likes.. now if there is any fiddling to be done, its done through accessor methods on object A. if object B does something to A that A cannot do, support or otherwise doesnt like, then the operation stops, not the entire program.

What is happening here is that you are creating a new Asdf called a. Then your passing in a reference to this new Asdf, but it now has a new name "b". "b", in the function is set to point at a new Asdf. However, a is still pointing at the original Asdf. Therefore, this function does nothing.
what's happening here is actually this:

//make objectA
(pointerA) ----> [objectA]
//function1(a); //actually in java we have METHODS, not functions
(pointerA) ----> [objectA] <---- (pointerB)
//b = new asdf();
(pointerA) ----> [objectA] &#160;&#160;&#160;&#160;&#160;&#160;&#160; (pointerB) ----> [objectB]


so the function (method) does actually do something; it makes a new object and point B to it instead. unfortunately then, it goes out of scope and both pointer B and object B are dissolved.

how is this a weakness?