[
https://issues.apache.org/jira/browse/GROOVY-3976?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-3976.
-----------------------------
> Alternative to "with" called "tap" that has an implicate "return delegate"
> --------------------------------------------------------------------------
>
> Key: GROOVY-3976
> URL: https://issues.apache.org/jira/browse/GROOVY-3976
> Project: Groovy
> Issue Type: Improvement
> Components: syntax
> Affects Versions: 1.7.0
> Reporter: Robert Fischer
> Assignee: Paul King
> Fix For: 2.5.0-alpha-1
>
>
> In this code:
> {code}
> class Foo { String bar }
> def x = new Foo().with {
> bar = "baz"
> }
> {code}
> "x" is now a String with the value "baz" thanks to the implied return. To
> work around this, we have to say:
> {code}
> def x = new Foo().with {
> bar = "baz"
> return delegate
> }
> {code}
> ...which is pretty ugly, to say the least.
> So can we modify the "with" syntax to have an implied "return delegate"? I
> doubt anyone was depending on the previous behavior for code correctness.
> Test will be this:
> {code}
> class Foo { String bar }
> def x = new Foo().with {
> bar = "baz"
> }
> assert x instanceof Foo
> assert x.bar == "baz"
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)