Feedback for records: Accessors name() vs. getName()
Brian Goetz
brian.goetz at oracle.com
Thu Aug 27 16:59:48 UTC 2020
I get your concern, and we'll think about what we can do. But in the
meantime, I think it's not quite as black-and-white as you paint it.
Frameworks that lean on reflection generally use a bag of tricks, not
just one trick, to try to infer design intent. Given that records have
a clear way to do this (Class::isRecord and
Class::getRecordComponents**), that's one more tool for the bag, which
can be added without dropping something else from the bag. There may be
other tools coming, but it's not either-or.
**You might ask why we call this `getRecordComponents` and not
`recordComponents`; simply, because this is an exisiting, extremely
widely used API that has already picked its conventions, and it was
deemed better to be locally consistent in this situation.
On 8/27/2020 11:55 AM, Roman Elizarov wrote:
> Brian,
>
> thanks for the detailed answer.
>
> > As I've hinted in other places, we want to generalize this notion of
> accessor to classes that are not records;
> (and interface, too, I suppose).
>
> And that's exactly my conundrum. I'd really like to see some guidance
> in this direction coming directly from Java and JVM platform. It would
> be best to see it at the same moment when records are
> released. Otherwise, there is a big risk of fragmentation in the
> ecosystem as different frameworks will start coming with different
> incompatible ways to mark the method as an accessor, the role that was
> historically a prerogative of "get" verb in the name, but now will
> have to be done in some other ways in light of records. As you
> correctly noted, frameworks will not have much choice but to designate
> an annotation for this role. Even if a JVM platform just introduces an
> annotation that does not do anything of much substance, but declares a
> developer's intent to have an accessor method, it would still be
> better than nothing and will help big time increasing consistency in
> the JVM ecosystem, just like the notion of "getXxx" getter methods was
> once brought in and codified by the JVM platform itself.
>
> Sincerely,
> Roman Elizarov
More information about the amber-dev
mailing list