Extended method reference - A proposal
Mahdi Mohammadi
mahdix at gmail.com
Tue May 17 19:41:40 UTC 2022
Thanks, Brian.
Regarding your first point, I don't consider them a "new type of method
reference" or a "parameterised method reference". This is a syntax sugar to
define a lambda which only calls another function.
About your second point, I agree that things like `_ < _` would be
confusing and not readable at all. Maybe we can limit this to lambdas with
only one argument? And, then it can be a concise way to curry functions.
On Tue, May 17, 2022 at 2:47 PM Brian Goetz <brian.goetz at oracle.com> wrote:
> People requested things like this during the design of lambda. You've got
> two features mushed together here:
>
> - Parameterization of method references with values;
> - Scala-style "wunderbar" to turn expressions with holes into lambdas
>
> Both have been proposed individually, but neither is all that attractive
> on their own, and don't benefit from combination.
>
> The first is a sort of "I love method references so much, I want to turn
> things that aren't really method references into method references." The
> result is something you won't love as much. Method references are nice
> because they are _symbolic_; a parameterized method reference is not.
>
> The second is not intrinsically terrible, but is not very compelling. It
> trades away readability for a little extra concision. Simple uses like `_
> < 10` are not all that bad, but when extended to multiple parameters, you
> get things like `_ < _`, which are neither that readable, *nor* are they
> good symbols for the `<` function! (Also, try inverting the order; you
> have to fall off the "cliff" back to `(x, y) -> y < x`.) But, "not all
> that bad in the simple cases" is not a raving endorsement for a language
> feature.
>
>
>
> On 5/17/2022 6:49 AM, Mahdi Mohammadi wrote:
>
> Hi,
>
> I have a proposal for the Java language to extend the way we use method
> references.
>
> Basically, instead of writing something like "*x -> obj.process(x,5)*" this
> should be simplified to "*obj::process(_,5)*". I believe this will simplify
> code, make it more concise and promote writing functional code.
>
> I'm looking for feedback from the community and also need help to make this
> a JEP. Here <https://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html> <https://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html> it
> mentions that I need help from an author, committer or reviewer to be able
> to do this.
>
> Thanks,
> Mahdi
>
>
>
More information about the amber-dev
mailing list