Extended method reference - A proposal
Brian Goetz
brian.goetz at oracle.com
Tue May 17 13:47:33 UTC 2022
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> 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