Point2D is immutable by design, so there are no setters. And yes, the private variables for x and y could be made final, but since that's not API it would just add a bit of clarity to the implementation.

-- Kevin


Sam Howman wrote:
Hi,

I'm wondering why there such a method or even setX/setY. I understand that
some classes prevent such manipulation of their initial values although it
seems like moving a point would be a very common thing to want to do. The
alternative would be to create a new Point2D whenever you would have
otherwise used "setLocation" (or similiar). This would probably be ok but
when there are say 100K points or more the impact on memory is significant.
So is there a good reason why they can not be changed once created? And if
this really is the intention should x and y be declared as "final"?

Regards,
Sam.

Reply via email to