Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.0
-
None
Description
In this code:
class Foo { String bar } def x = new Foo().with { bar = "baz" }
"x" is now a String with the value "baz" thanks to the implied return. To work around this, we have to say:
def x = new Foo().with { bar = "baz" return delegate }
...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:
class Foo { String bar } def x = new Foo().with { bar = "baz" } assert x instanceof Foo assert x.bar == "baz"
Attachments
Issue Links
- is duplicated by
-
GROOVY-4442 'with' method should return the object in which it was called
- Closed
- relates to
-
GROOVY-5788 Add inline() method to Object
- Closed