Quote:Original post by BCullis
What tripped me up was the transition to "reference by default". Where C++ passes by value, Java will always pass by reference because all objects are treated like references. (and if I just horribly mis-described that, someone more knowledgeable feel free to smite me, this is just how it was explained to me).
This was stated a bit wrong. Java passes every reference by value. So, passing a reference of an Object to a method, inside the method you will have a new reference variable that contains the same value as what was passed to it. If you assign a different object, or a new object to that local variable, the original reference passed to the method will not lose it's reference to the original object, and will not point to the new one created.
public void foo(Object obj2){ //The local variable obj2 now contains a reference to a new Object obj2 = new Object();}Object obj1 = new Object();foo(obj1);//obj1 still points to the original object