declaration-site extension methods possibly dangerous
Fatih Coskun
fatih at coskuns-castle.de
Sat Dec 12 03:25:20 PST 2009
Rémi Forax wrote:
> I don't think that it's a good idea to be able to hide an extension
> method. [...] the compiler can raise an error, as it do when you try
> to override a static method
> with a non-static one.
>
>
Extension methods are about adding methods to interfaces without
breaking existing code. What happens, if someone has defined an instance
method, which is later added as an extension method in the class'
super-interface? We can't raise an error, as that would break existing code.
>> Because use-site extension methods are not defined in the interface,
>> one will not be tempted to override them. The developer will not be
>> tempted to do something that can't be done.
>
>
> Why, it's an extension method. By definition, you call it on an
> instance, so you will want to override it. It's a problem of all
> extension methods.
>
>
Maybe. But use-site extension methods are less likely to be confused
with instance methods in my opinion. Besides that, it may be easier to
explain why it is not possible to override use-site extension methods.
More information about the lambda-dev
mailing list