Hi Rémi,

      'this' inside the closure references the instance of enclosing class, so 
no difference exists in the semantic of 'this'.

PS: I verified it using groovy2.4.7

Cheers,
Daniel.Sun



在 "Remi Forax [via Groovy]" 
<ml-node+s329449n5736202...@n5.nabble.com>,2016年10月19日 下午7:17写道:

Hi Cedric,

________________________________
De: "Cédric Champeau" <[hidden email]>
À: [hidden email]
Envoyé: Mercredi 19 Octobre 2016 09:09:51
Objet: Re: Lambda expression for Groovy 3
First of all, great work, Daniel ! I'm confident that making the "lambdas" be 
"closures" in Groovy is enough. I stated it in the past but I'm going to repeat 
myself here, I don't think having 2 syntax for "closures/lambdas" with slightly 
different semantics would help our users/language. That said, the static 
compiler can do better, doing escape analysis, and using "real" lambdas when 
the target bytecode is 8, as an optimization.

The main issue i see of having one semantics is that the meaning of 'this' in a 
Groovy closure means the closure itself while 'this' in a Java lambda means the 
enclosing object, so { -> this } in Groovy is a substitute to () -> this in 
Java.
The choice seems to be, the semantics of 'this' in a lambda in Groovy can be 
either the same as Java so you can copy/paste a Java code and it will work as 
is in Groovy or the same semantics as in a Groovy closure so as you said you 
will not have to explain why in Groovy { -> this } and () -> this do not return 
the same value.

I have no opinion about that, i let you guys decide :)

That said, the lambda metafactory takes a desugared lambda as argument (a plain 
old static method, apart in corner cases), so choosing the semantics of the 
lambda in Groovy is orthogonal to the choice of using the lambda metafactory or 
not.

Rémi



________________________________
If you reply to this email, your message will be added to the discussion below:
http://groovy.329449.n5.nabble.com/Lambda-expression-for-Groovy-3-tp5736169p5736202.html
To unsubscribe from Lambda expression for Groovy 3, click 
here<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5736169&code=cmVhbGJsdWVzdW5AaG90bWFpbC5jb218NTczNjE2OXwxMTQ2MjE4MjI1>.
NAML<http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: 
http://groovy.329449.n5.nabble.com/Lambda-expression-for-Groovy-3-tp5736169p5736217.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Reply via email to