New JEP: Concise Method Bodies
Kevin Bourrillion
kevinb at google.com
Fri Oct 5 20:25:28 UTC 2018
Oops - sorry for the rapid-fire responses here. A couple more points while
this is all still actively rattling in the brainpan.
Today, method references are a thing, and can be bound to expressions:
`foo()::bar`.
A piece of folk knowledge that we count on developers to pick up along the
way is that the `::` separates that which is evaluated now from that which
is evaluated later. Any who don't grasp that will eventually get into some
trouble sooner or later.
Now we want to introduce a second way to use method references, where that
creation/evaluation distinction doesn't exist. Or does it? *Some* number of
users will think "maybe what's before the :: is evaluated the first time
the method is called and then reused? In fact, I think I remember learning
something just like that... they were really clear about the difference
between what's before vs. after the ::. This must be it." This is
problematic.
Finally, to my earlier screed about the trade-offs of "multiple ways to do
the same thing" I want to add a nice (very paraphrased) point that was made
on reddit by a now-deleted account. (Thanks, mystery person.) Offering
users a choice between two ways to do the same thing isn't *just* offering
them a choice. It's also burdening them with having to read and maintain
code that made each of those choices, for whatever reasons that may be
unknowable now. Now, no one in amber-spec-experts will say "I never thought
of that before", but I'm just explaining why I'm advocating for a high bar
here.
On Fri, Oct 5, 2018 at 1:03 PM Kevin Bourrillion <kevinb at google.com> wrote:
> On Mon, Sep 24, 2018 at 10:17 AM Alex Buckley <alex.buckley at oracle.com>
> wrote:
>
> On 9/21/2018 4:07 PM, Kevin Bourrillion wrote:
>> > "The method reference form can use most kinds of method references after
>> > the = sign: static and unbound method references, bound method
>> > references (if the receiver *variable* is in scope for the method
>> > declaration)"
>> >
>> > Can we still bind to any expression?
>> >
>> > private String a(String b, int c)
>> > throws SomeCheckedException = *d.e()*::f;
>>
>> No limitation is intended on the receiver, as long as the method
>> reference expression would be legal if it appeared in the traditional
>> body of method `a`. (Details of this translation remain to be worked out.)
>>
>
> Can the expression before the :: refer to any method parameters? Of
> course, it would still expect to pass those parameters into the method, so
> it's *weird* to have the same parameter used in both ways, but does it
> make sense to forbid it?
>
>
> --
> Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
>
--
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20181005/97e6d7dc/attachment.html>
More information about the amber-spec-experts
mailing list