State of the Lambda

Brian Goetz brian.goetz at
Thu Jul 8 12:02:47 PDT 2010

> The syntax for specifying the target type in a method invocation context
> seems awfully confusing. The draft says:
>      executor.submit(Callable<String> { -> "foo"} );
> That looks a heck of a lot like a cast, except it's missing the parens.
> People will therefore tend to put them in by accident:
>      executor.submit((Callable<String>) { -> "foo"} );

Indeed, the (CICE-inspired) approach of "stick the type in front of the block" 
looks an awful lot like a cast.  We went back and forth a few times on this. 
The main reasons in favor of this approach are:

  - We have left undefined the type of a naked lambda expression, because it 
is target-typed.  Most of the JLS describes casting rules in terms of 
from-A-to-B.  If we don't know the type of A, it is not really a cast.

  - If we intend to support abstract classes as SAM types (and we do) and we 
intend to support use of non-default-constructor (which we might), there needs 
to be a place to put the constructor arguments.  One choice is to punt and say 
"use anonymous classes there."  Another is to do something really CICE-like:

       executor.submit(new Callable<String>(args) { -> "foo"} );

("new" is optional here; everyone will have opinions.)

A cast does not address this problem.

More information about the lambda-dev mailing list