[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-dev
Subject:    Re: [groovy-dev] interesting bug
From:       Jochen Theodorou <blackdrag () gmx ! org>
Date:       2008-06-26 9:56:58
Message-ID: 486367EA.4080702 () gmx ! org
[Download RAW message or body]

Alex Tkachman schrieb:
> 1st of all I am sorry for my last commit, which broke trunk. I don't
> know why I thought that I've run full test suite before commit.
> 
> Now about nature of the problem.
> 
> Groovy-2138 asks for DGM method Object#plus(String) is needed, which
> seems to be very natural. So I implemented Object#plus(CharSecuence)
> and wrote simple test
> 
>       def x = new Object()
>       assertEquals ("${x}239".toString(),  x + "239")
>       assertEquals ("239${x}777".toString(), "239" + x + 777)
>       assertEquals ("${x}Builder${x}".toString(), x + new
> StringBuilder("Builder") + x)
> 
> But they life is not so simple.
> 
> We have GString GString#plus(String) which clashes because interfaces
> has preferences to inheritance in Groovy.

that sounds not quite right...GString#plus(String) called with a String 
should not call Object#plus(CharSecuence). You are saying this is the case?

Btw, the code for single argument dispatching is different from the code 
for multiple argument dispatching, it is quite possible, that the single 
argument dispatching has one or two not yet discovered problems.


> We also have List#plus(Object) which also clashes when called with
> String parameter.

clashes in the sense that Object#plus(CharSecuence) is preferred when a 
String is given... that one looks right to me... if you want to have 
that fixed, you have to override that method

> So far I reverted my fix and reopen the issue but here are 2 questions:
> 
> 1) Specific one: what is right way to implement this particular
> functionality. Or is it any cheap way to implement it.

adding methods to object, that are used on other Objects as well is 
always a bit critical. Even if you would have added only 
Object#plus(String), you would still have the problem with 
List#plus(Object). I guess there is no other way, but to override the 
method if you want to keep Object#plus. I think it is not such a big 
deal to have to write ""+x+"foo", instead of x+"foo".

> 2) General one: how to approach such situations in general? I can
> imagine checking meta class and doing default operation only if
> nothing better was found but I don't like that a lot.

Sorry, can't follow you. Can you explain this a little?

bye blackdrag

-- 
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic