Hi Jochen,
could you be more precise about where you see the problem(s) in your
example:
1) That Wrapper is not an immutable class, and you can therefore change
its state after creation ?
2) That GString $-expressions (outside of "${-> ...}") do not capture
the expression, but the result of evaluating the expression (which
oftentimes will be an Object referece) ?
3) That GString is not immediately evaluated to its String representation ?
4) ... ?
And what you would accordingly want to see improved and how ?
Cheers,
mg
On 10.09.2018 20:33, Jochen Theodorou wrote:
On 10.09.2018 18:51, Alessio Stalla wrote:
Yes, but a toString method with side effects is a really bad coding
practice that won't be fixed simply by reducing the power of GString.
well...
class Wrapper {
def x
String toString(){x}
}
def w = new Wrapper(x:1)
def gstring = "$w"
assert gstring == "1"
w.x = 2
assert gstring == "2"
w = new Wrapper(x:3)
assert gstring == "2"
I don't think that example really falls under your really bad coding.
You have this problem with lists and maps all the time
bye Jochen