Value types and parameter names

Lovro Pandzic lovro.pandzic at gmail.com
Mon Dec 22 09:48:54 UTC 2014


>
> The counterpart of a "setFoo" method for an immutable class would be "withFoo":
>
>     final __ByValue class Point {
>         public final int x, y;
>         public Point(int x, int y) { this.x = x; this.y = y; }
>         public Point withX(int x1) { return new Point(x1, y); }
>         public Point withY(int y1) { return new Point(x, y1); }
>     }
>
> I think the same clunky tricks as can be done for "setters" can also be done for "with-ers".
>
> (Word note:  "wither" has unpleasant connotations compared to "setter".  A setter is a nice dog, a wether is a sad goat.)
>
> The awkwardness of working with "with-er" methods is well-known.  For example, in a paper I was just browsing:
>
> I guess for value types this wouldn't incur any significant cost as it
would for objects.
My personal preference is to use constructors if it is possible and
acceptable in terms of readability, but "with-ers" are a nice alternative.

Anyone know the answer for

> On the side note, is there an option to get classes with the JDK with
> parameter names? (like String, Integer, etc)
>
>

Lovro Pandžić



More information about the valhalla-dev mailing list