Why there was a need to use default methods in Interface

Paul Benedict pbenedict at apache.org
Sun Mar 31 18:46:32 PDT 2013


Just like the compiler will issue an error when an "abstract" method has a
body, the compiler will issue an error if a "default" method lacks a body.
The use of keyword makes the intention of the developer explicit.


On Sun, Mar 31, 2013 at 5:12 PM, William Clark <wclark1324 at comcast.net>wrote:

> In addition to what Brian said, "default" is not only used for
> interfaces; it's also used in switch statements and annotation definitions.
>
> On 3/31/2013 3:18 PM, Mrityunjay Sharma wrote:
> > Hi Brian,
> >
> > My question is more about on why mark the method as default explicitly,
> > when compiler can perform the task for me (marking the implementation in
> > interface as default). With this there will be one less keyword which is
> > used only for interfaces.
> >
> > Thanks & Regards,
> > MJ
> >
> >
> > On Mon, Apr 1, 2013 at 12:42 AM, Mohammed Sanaulla <
> sanaulla123 at gmail.com>wrote:
> >
> >> 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