Now I may be totally off the mark here, so maybe people can put me straight…
Imagine the handy little class ‘Vector2f’, just a simple little math class. Now in C++ I’d happily write:
const Vector2f getPosition();
to get an objects position, safe in the knowledge that who ever is calling the method can’t tinker with the returned object. All well and good. But the Java equivilent would be without any sort of ‘const’ modifier, and so open up the class to be modified in an unintended way, bypassing the intended set method.
‘final’ to the best of my knowledge, just makes the reference final, not the actual data, and is therefore not a substiture. So the alternative would be
void getPosition(Vector2f dest);
and having a blank object into which the new information is copied. That or return a copy, but both of these need an extra object to be created just to hold what will likely be a temporary result.
Now I may be being overly paranoid about the GC, but this is getting to be really annoying. I don’t like possibly creating hundreds of tiny little objects per frame, and the alternative of keeping them around (or a small number of temporary ones around and reusing them) gets ugly when used to any large extent.