groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessio Stalla <alessiosta...@gmail.com>
Subject Re: [Proposal] GString is implemented eager and treated as normal String since groovy 3.0.0
Date Mon, 10 Sep 2018 19:20:37 GMT
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 <blackdrag@gmx.org> 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
>

Mime
View raw message