Why there was a need to use default methods in Interface
Brian Goetz
brian.goetz at oracle.com
Sun Mar 31 12:05:04 PDT 2013
Interface evolution.
Interfaces like Collection cannot be added to, because there are already
implementations of Collection out there, so if we added a method to
Collection, it would render all existing implementations not
compileable. This means that interfaces like Collection could not be
evolved once published.
Default methods provide a path to evolving interfaces over time, as it
lets you compatibly add to an interface as long as the functionality you
want can be expressed in terms of existing interface methods.
On 3/31/2013 2:48 PM, Mrityunjay Sharma wrote:
> Hi All,
>
> I have a question regarding providing the support for adding default method
> in interface.
> When we are adding an implementation in interface, compiler can itself
> decide whether its an default implementation or not. As far as i know we
> cannot use default methods for any class, instead we can only use it in
> interfaces. Then why there was a need to use default methods.
>
> Thanks & Regards,
> Mrityunjay
>
More information about the lambda-dev
mailing list