Details
-
Sub-task
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.5.4
-
None
-
None
Description
If toString is overridden via the metaClass then "${obj}" != obj.toString().
Test case below
class DateTest extends GroovyTestCase { void testToString(){ Date.metaClass.toString = { -> 'boogie' } def date = new Date() assertEquals('boogie', date.toString()) assertEquals( date.toString(), "${date}") //fails } }
Paul King gave this pointer as to where the problem is:
"Yes, the final line of InvokerHelper.format() should be something like:
return (String) invokeMethod(arguments, "toString", EMPTY_ARGS);
//return arguments.toString();
to make your example work."
Attachments
Issue Links
- is duplicated by
-
GROOVY-2732 GString doesn't call correct toString method when it's been changed via the metaClass mechanism
- Closed
- is related to
-
GROOVY-10073 Unable to use custom string representation in GString template
- Open
- relates to
-
GROOVY-2801 Override toString in coerced Map fails for interfaces but is ok for concrete classes
- Closed