Quote:Original post by Anonymous PosterQuote:Original post by Fred304
In other words, you cannot change the reference. As already pointed out, the reference is passed by value.
It's perfectly correct to say that in Java all objects are passed by reference. If you change some attribute of the passed class that you'll be changing it in the same instance passed. This is useful in real world.
Your example does not meet "real world" work. Why a Java programmer would want to change the instance inside of a method? The only people I found complaining about this were C++ developers trying to find a pretext for bashing Java.
No, it's not. Objects are passed by value. The only reason your changes in the function affect the passed instance of the class is that both pointers, the one in the function and the one outside the function, point to the same instance of the class. The pointer is passed by value, but it's value is the class instance. If you, inside the function, made the passed pointer point to something else, the pointer on the outside of the function would still be pointing to the original instance. If you passed by reference, it would be pointing to whatever you stated in the function.
There's a few examples I can think of that are "real world", but references don't do anything more than pointers could do. And since everything in Java is a pointer, the lack of references is basically insignificant.