I've recently been reading about the behavior of GStringImpl
s vs String
s when used in collections in Groovy.
I understand that the reason this evaluates to false...
"${'test'}".equals("test") == false
is due to the symmetry requirement of the .equals()
contract, however I was wondering if there was a reason the GStringImpl
couldn't just be evaluated to a String
immediately. So when I do something like this...
"${'someString'}"
I don't get a GStringImpl
, I just get a plain Java String
back, which I can immediately use as the key in a map, for example.
I know there are some workarounds, like
String s = "${'someString'}"
however stuff like this is a bit inconvenient, and the mix-up between GStringImpl
and String
seems to be a big 'gotcha' for Groovy newbies.