Am 16.03.2014 21:50, schrieb OC:
> Hello there,
>
> looks like String/Number are ambiguous, whilst String/Integer are _not_ ambiguous. Does it make sense? How comes?
so basically the question is about foo(null) with an foo(String) and
foo(Number) being available and why it fails.
Not sure I mentioned it already to you, but in case I did not, I do it
now. Groovy has an "distance" (inheritance wise) based approach. That
means we get the "distance" from the runtime type to the actual type
provided by the method. Normally the method with the smallest distance
wins, but in case of null there is no such type, so we go for the most
general method (smallest distance to Object).
Now looking at String we have Object as direct parent. In case of Number
too. And since interfaces are not used in this case the result is that
both have the same distance and thus the call is ambiguous.
In case of Integer it is not ambiguous, because Integer extends Number,
thus the distance is higher
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog:
http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit
http://groovy-lang.org