First, remember that a .NET String
is both IConvertible
and ICloneable
.
Now, consider the following quite simple code:
<
Another explanation: there is no ambiguity, therefore there is no compiler warning.
Bear with me.
ICanEat wolf = new HungryWolf();
wolf.Eat("sheep");
There is no error because ICanEat
only contains one method called Eat
with those parameters. But say this instead and you do get an error:
HungryWolf wolf = new HungryWolf();
wolf.Eat("sheep");
HungryWolf
is ambiguous, not ICanEat
. In expecting a compiler error you are asking the compiler to look at the value of the variable at the point at which Eat
is called and work out if it is ambiguous, which it not necessarily something that can it can deduce. Consider a class UnambiguousCow
which only implements ICanEat
.
ICanEat beast;
if (somethingUnpredictable)
beast = new HungryWolf();
else
beast = new UnambiguousCow();
beast.Eat("dinner");
Where and how would you expect a compiler error to be raised?