Package Private Record Fields
Mateusz Romanowski
romanowski.mateusz at gmail.com
Tue Apr 28 20:45:22 UTC 2020
Hi August,
Have you considered putting "friend" methods in the same source file, and
therefore using nest-based access control?
Cheers,
Mateusz
On Tuesday, April 28, 2020, August Nagro <augustnagro at gmail.com> wrote:
> I'm enjoying using the Records preview so far.
>
> One thing I've noticed is that classes in the same package as the Record
> are likely to be heavy users of its public accessor methods, and that the
> `()` can inhibit readability. For example,
>
> org/example/Point.java
> record Point(double x, double y) {}
>
> org/example/MathFunctions.java:
> import static java.lang.Math.*;
>
> class MathFunctions {
> public static double distance(Point a, Point b) {
> return sqrt(pow(b.x() - a.x(), 2) + pow(b.y() - a.x(), 2));
> }
> }
>
> It would be nice to be able to write:
>
> class MathFunctions {
> public static double distance(Point a, Point b) {
> return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.x, 2));
> }
> }
>
> I understand the reason for not making them public.. the accessor methods
> are good API design. But giving Record fields the default modifier
wouldn't
> change this.
>
> Regards,
>
> August
>
More information about the amber-dev
mailing list