Polygons... returning and passing objects?
Let's say I have a Polygon class and it has an ArrayList of Point2D.Double objects acting as its vertices (this.vertices).
When I instantiate it, and then do something like this:
Point2D.Double point = myPolygon.getVertex(2);
I am able to change the vertex INSIDE the instantiation by doing this:
Is this something to worry about? I think that I want it so that I have an ArrayList of values that can be changed inside an object, where what goes into the array from outside isn't 'linked' to anything else in this way, and what is read outside from the array isn't 'linked' to anything else in this way.
Do I just put .clones() everywhere a value goes in and out? That seems dense and redundant to me.
Any advice? I can post the whole Polygon class here if anyone wants to see it (or if that's possible).