But this is not necessarily a problem. It's how mutable objects work. GString is mutable, transitively. If you want to convert it into an immutable type, you can already - by calling toString on the GString.
Daniel's example and rationale are about side effects inside the toString method itself. Which /is/ really poor practice. On Mon, Sep 10, 2018, 20:33 Jochen Theodorou <[email protected]> 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 >
