groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Automatic closure coercion and delegate
Date Mon, 02 May 2016 16:11:27 GMT
On 02.05.2016 16:44, Cédric Champeau wrote:
[...]
> Of course, it may look a bit superficial but it is super important for
> nice DSLs like in Gradle.

could you give an example of a more complex closure usage?

We should be also aware that this change may break code, since it is 
semantic change and a local method of the same name will no longer be 
called if it exists on the delegate. A functional interface is after all 
not something that came really to exist with java8 only, Callable and 
Runnable are examples that existed before and work with Closure already.

Implementation wise to have something like

> void configure(Action<Person> config) {
> config.execute(person)
> }

working we need to set the delegate to person, but we don´t know person 
before the method invocation. This means the proxy for the Action 
delegating to the closure config represents must also make the 
delegation setter call.

And there is also the problem of what we do if Action contains default 
methods - I do not consider our current solution as appropriate anymore. 
But of course that is not essential for the idea at hand.


bye Jochen

Mime
View raw message