Why no placeholder shortcuts for lambdas?

Antoras mail at antoras.de
Tue Mar 6 12:25:25 PST 2012


Ok, I will read that. Thanks for the responses.


On Tue 06 Mar 2012 09:07:05 PM CET, Richard Warburton wrote:
>
>>
>> I'm wondering why the shortcuts for lambdas are not as short as they 
>> can be.
>>
>> For example I get the following to work:
>>
>> xs.foldLeft(0, (i1, i2) -> i1 + i2);
>> xs.foldLeft(0, ListTest::add);
>>
>> static int add(int i1, int i2) {
>> return i1+i2;
>> }
>>
>> where xs is a list of ints, foldLeft a method of this list and add a
>> method in a class ListTest. But what was the design decision to disallow
>> the following:
>>
>> xs.foldLeft(0, (+))
>> // or
>> xs.foldLeft(0, (_+_))
>> // => (obj1).+(obj2) for objects
>> // => (prim11)+(prim2) for primitives
>>
>> where + can be a method of an object or an operation on primitives and _
>> any placeholder.
>>
>> Is this technically impossible or are there other reasons?
>
>
> This has been discussed on the list before, the thread in
> http://mail.openjdk.java.net/pipermail/lambda-dev/2011-September/004025.html
> provides some comments. My tl;dr is that the EG thought there was
> very little benefit gained by this syntactic sugar for the added
> complexity.
>
> regards,
>
> Richard
>


More information about the lambda-dev mailing list