no Point2D.setLocation(x,y)?

Kevin Rushforth kevin.rushforth at oracle.com
Thu Jul 30 03:14:02 UTC 2015


Since it is private, I'm not sure, but it couldn't hurt and is a good 
idea -- NetBeans suggests making it final, since it can be.

Jim Graham wrote:
> Would adding final to the field declarations also aid in the 
> inline-ability of the getters?
>
>             ...jim
>
> On 7/29/15 5:32 PM, Kevin Rushforth wrote:
>> 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