groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remi Forax <>
Subject Re: [VOTE]About the implementation of lambda expression
Date Tue, 07 Feb 2017 17:13:55 GMT
Hi Daniel,

On February 7, 2017 5:20:11 PM GMT+01:00, Daniel Sun <> wrote:
>Hi all,
>      Jesper and I discussed the *real* lambda expression(i.e. Java8's
>lambda expression) just now. As Jesper found, Java8's lambda expression
>implemented in Java as an invokedynamic call which makes use of a
>method calling into a class called the LambdaMetafactory
>and puts the body of the lambda expression into a hidden method on the
>class. The LambdaMetafactory sets up the magic class which holds any
>variables and implements the functional interface. To work, it requires
>EXACT type information,* so it's only possible to do this in static

It's not fully true.
javac generate a lambda body with the exact type info so the lambda proxy class has to be
created with the exact info, if the groovy compiler desugar a lambda body using Objects, the
lambda factory will only need Objects. 
Also, the groovy compiler do not have to call the bootstrap method of the lambda meta factory
directly so the runtime can also find the target dynamically if that info is available and
ask the user to insert a cast to the interface otherwise.
You can also imagine that the groovy runtime can use the interfaces of java.util.function
if no interface is provided an do a lambda to lambda conversion at runtime if the number of
parameters match but not the interface.

>  Current lambda expression is based on closure, so it can work well in
>the default mode and static compilation mode. But if we want the *real*
>lambda expression, it will be only available in the static compilation
>mode(as above said). When developers does not enable static
>compilation, we
>provide them lambda expression based on closure or provide no lambda
>expression at all? I prefer the universal version of lambda expression,
>lambda expression based on closure with some warning(such as changing
>delegation strategy of 'this' is forbidden, reference:
>- [ ] A, lambda expression based on closure with warning(or error
>- [ ] B, *real* lambda expression is available *in the static
>mode* while lambda expression based on closure is available *in the
>- [ ] C, *real* lambda expression is only available *in the static
>compilation mode* while *no lambda expression* is available *in the
>P.S. My vote is A

Java lambdas are identity less so there is more than just how this/super behave, as an example,
an array of lambdas can be differently than an array of reference. 

And also please do not forget that the code of the meta factory can change for any updates
of the JDK.



>View this message in context:
>Sent from the Groovy Dev mailing list archive at

Sent from my Android device with K-9 Mail. Please excuse my brevity.

View raw message