no Point2D.setLocation(x,y)?

Kevin Rushforth kevin.rushforth at oracle.com
Thu Jul 30 00:32:48 UTC 2015


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.
>   


More information about the openjfx-dev mailing list