Defender Extension Methods -- Resolution and Invoccation
Mike Duigou
mike.duigou at oracle.com
Wed Aug 4 14:49:36 PDT 2010
From Maurizio's Sytax samples Doc:
> 3. Defender Methods
> -------------------
>
> Defender methods are declared using the 'extension' keyword, as follows:
>
> extension List<T> map(Mapper<T> r) default Collections.<T>listMapper;
>
> A defender method declaration is structured in two parts, (i) a method signature, declaring formal arguments, formal type-arguments and return-type and (ii) a default implementation, that is, the implementation the method should default to if none is found in the class implementing the extended interface.
Have you considered extensions with no default? I understand that the defender is primarily intended to support interface evolution but providing a default implementation isn't always practical. I'd prefer to see a "missing implementation of xyz" compile error to a usage pattern which involves default methods who's only purpose is to generate a runtime exception for the unsupported operation.
Is the resolution of the extension method intended to occur at compile time or at invocation time? ie. will compiled code which refers to the extension method include a call to the named method through the interface or a call to the static default method. For greatest flexibility in interface evolution it would be much more useful if the resolution happens at the time the method is invoked.
Mike
More information about the lambda-dev
mailing list