Maybe I still miss an important concept.
To allow reading and prevent writing of non-primitive members, the according getter always creates a new copy of the member object. I want to prevent this for performance reasons. I am trying to write a simple 2D simulator with collision detection based on a quadtree and this would be bread and butter.
I think in C++ I can do it with the return of a const. (I know I can overwrite this with a cast) but I am not sure how this is done in JAVA.
any ideas?
There are several ways to archive what you want to do.
First of there is no language support for what const does in C++.
In any case I suggest you use Getters and Setters as there is no overhead caused by them what so ever. The Java just-in-time optimization takes care of this.
For non-primitive types you still have the problem that the object you returned itself could get changed. There are three ways to prevent this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With