The lambda conversion and a lambda body that doesn't complete.
Brian Goetz
brian.goetz at oracle.com
Tue Mar 1 11:10:19 PST 2011
Neal;
Thanks for the note. You're right that the current prototype doesn't deal with this properly. The good news is that the draft spec we're working on -- and will present to the JSR 335 EG soon -- already addresses this issue.
On Mar 1, 2011, at 9:35 AM, Neal Gafter wrote:
> Dear Lambdans-
>
> Given
>
> *interface F {
> int invoke();
> }*
>
> I would like to be able to write
>
> *F x = #{ throw new Exception(); };
> *
>
> (Modulo syntax - whatever the current syntax is)
>
> But according to the current draft specification that's not allowed (the
> lambda as written can only be converted to a SAM with a void return type).
>
> I think that whether or not the lambda's body can complete normally should
> be taken into account in the lambda conversion to make this legal. As a
> point of information, the behavior I prefer is the behavior of Scala, BGGA,
> and C# (among others). This is also consistent with the way method
> implementations work:
>
> *int f() { throw new Exception(); }*
>
> In the unfortunate case that you need use cases for this, draft
> specification language, or suggestions for a straightforward implementation,
> I can provide those.
>
> Cheers,
> Neal
>
More information about the lambda-dev
mailing list