Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
The Script
class Test {
public String toString() { super.toString() + properties }
}
println new Test()
produces:
Test@2a5330["metaClass":groovy.lang.MetaClassImpl@1b383e9[class Test], "class":class Test]
but the Script
class Test {
public String toString() { new StringBuffer(super.toString()).append(properties) }
}
println new Test()
produces:
Test@13c1b02{metaClass=groovy.lang.MetaClassImpl@91cee[class Test], class=class Test}
Is that a bug? I would think this should produce the same result. If the first class would be compile it should generate something like the second class. So this could also be a difference between scripts and compiled code? (I will try this if I got the time.)
Issue Links
- relates to
-
GROOVY-2331
Println behavior for collections, strings and gstrings [minor breaking change]
-
Hm,... so other versions of the script:
class Test {
public String toString() { super.toString() + properties.toString() }
}
println new Test()
and
class Test {
public String toString() { super.toString() << properties }
}
println new Test()
produce the second result again:
Test@13c1b02{metaClass=groovy.lang.MetaClassImpl@91cee[class Test], class=class Test}
So, is something wrong with the + operator for Strings in scripts?
PS: I used Groovy 1.5.0