Some objects are constant in that they do not allow their users to modify their state: all the primitive wrappers, String, the additional number classes. Even if they are passed by reference (as they are), you cannot modify them. It's like passing a pointer to an object in C++, where the object pointed to has a private assignment operator, no public properties and no methods that modify any internal values. You can change the pointer, but not the object. Still, the object was passed by reference.
But you can for example pass a StringBuffer to a function and modify it there. The modification will be visible outside the function because the StringBuffer was passed by reference. To pass an object "pseudo-by-value", you have to do something like
StringBuffer sb = new StrinBuffer();
The other one is to create a new vector on the heap in the function and then return a pointer to it.
Something I don't like at all. I can't stand functions that allocate stuff and return a pointer to it if there is no logical end function that deletes the memory.
Originally posted by CornedBee
The references are passed by value, but the objects are passed by reference.
You may say so in everyday speech but technically it's NOT correct. This example is from p. 145 in the C++ book by Stroustrup,
void f(int val, int& ref)
The first argument is passed according to the pass-by-value mechanism, the second is passed using pass-by-reference. It doesn't matter what you pass, the whole difference is in the passing MECHANISM. In the example the arguments are int's but they could as well have been references (pointers to objects). It wouldn't have changed anything.