[josm-dev] EastNorth immutable and cloning

Sebastian Klein bastikln at googlemail.com
Tue Nov 16 20:04:56 GMT 2010


Olivier Croquette wrote:
> Hi all
> 
> While implementing my improvements for PicLayer, I came upon 2 issues in the core code.
> NB: while I know other languages quite well (in particular C++ and Perl), I am a Java newbie. That may explains things ;-)
> 
> 1) First, it's documented as a immutable class : 
> 
> /**
>  * Northing, Easting of the projected coordinates.
>  *
>  * This class is immutable.
>  *
>  * @author Imi
>  */
> public class EastNorth extends Coordinate {
> 
> 
> But Coordinate.setLocation(x,y) allows to modify the state of EastNorth instances, so in my understanding, EastNorth is mutable, and therefore the doc is wrong.

Another example is the hierarchy of classes CachedLatLon > LatLon > 
Coordinate. Here LatLon is immutable, but Coordinate and CachedLatLon is 
not. I guess it is immutable "by contract" so it is simply forbidden to 
use setLocation() on a LatLon object (although it is not technically 
enforced by the compiler).

Call it bad design, pragmatism or insufficiency of the OOP paradigm.

> 2) In NavigatableComponent :
> 
>     /**
>      * @return Returns the center point. A copy is returned, so users cannot
>      *      change the center by accessing the return value. Use zoomTo instead.
>      */
>     public EastNorth getCenter() {
>         return center;
>     }
> 
> The doc is misleading. With the statement "A copy is returned"

I agree, doc should be updated.

Sebastian



More information about the josm-dev mailing list