declaration-site extension methods possibly dangerous

Rémi Forax forax at
Sat Dec 12 04:41:54 PST 2009

Le 12/12/2009 12:25, Fatih Coskun a écrit :
> 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. 

No, just adding method to an interface (see below).

> 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.

Yes, it will break existing code, like introducing a new public method 
in a class
can break code. In real world, this kind of breakage doesn't appear 
often, I don't think it worst the cost of
not raising an error is you try to override an extension method.

Note that introducing an extension method can break the code in a more 
malicious way
if the extension method overload an abstract method of the interface.

interface Map<K, V> {
   V get(Object o);
   V get(String s) import static Optimizeds.get;


More information about the lambda-dev mailing list