Why there was a need to use default methods in Interface

Mohammed Sanaulla sanaulla123 at gmail.com
Sun Mar 31 12:12:20 PDT 2013


I think the query was why to use "default" keyword in the interface while
providing the implementation. It could have been skipped and instead allow
the compiler to identify that any implementation in an interface would be
default method.
Please correct me if I misinterpreted the question.

Mohamed Sanaulla <http://blog.sanaulla.info> |
http://in.linkedin.com/in/mohamedsanaulla


On 1 April 2013 00:35, Brian Goetz <brian.goetz at oracle.com> wrote:

> 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