Why no placeholder shortcuts for lambdas?

Antoras mail at antoras.de
Tue Mar 6 11:56:04 PST 2012


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?

Thanks in advance
Antoras


More information about the lambda-dev mailing list