Package Private Record Fields

August Nagro augustnagro at gmail.com
Tue Apr 28 20:51:28 UTC 2020


Hi Mateusz,

How would that improve the readability? Can you share an example?

On Tue, Apr 28, 2020 at 3:45 PM Mateusz Romanowski <
romanowski.mateusz at gmail.com> wrote:

> 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