What should default interfaces be for?
anthony.vanelverdinghe at gmail.com
Wed Mar 14 11:47:55 PDT 2012
I dislike the idea of allowing implementation inside interfaces, so I
see default methods as a necessary evil for interface evolution. And I
fully agree with the view that developers should not implicitly depend
on default methods. Even more: why not let the Java compiler emit a
warning when classes do depend on default methods?
PS: in case it wouldn't be clear by now: I 'm against allowing Object
methods as default methods :)
Kind regards, Anthony
Op 13/03/2012 11:18, Stephen Colebourne schreef:
> On 13 March 2012 00:10, David Holmes<david.holmes at oracle.com> wrote:
> David said:
>> I'm concerned that default methods are being seen as a new way to
>> construct type hierarchies, rather than just being a short-term way to
>> add a new method to an existing interface. In my opinion developers who
>> subclass interfaces to which default methods get added, should implement
>> those new methods in the next version of their libraries/apps - so that
>> they don't rely on implicit use of defaults (they can make it explicit
>> if it suits their needs). Default methods provide an evolution path for
>> interfaces, but they can very easily be mis-used.
> I think that in all the focus on lambdas, there hasn't been enough
> discussion of what the Java community wants from the defaulted
> interfaces feature.
> David expresses the original lambda-focussed opinion - that default
> methods in interfaces solely exist to provide a mechanism for
> interface evolution. A necessary evil to provide the ability to
> integrate lambdas into existing APIs but not for general use as part
> of API design.
> I've come to the opposite opinion. That defaulted interfaces are a
> major new language feature in their own right, and should be
> celebrated as such. I want to use them as a new way of designing
> applications, replacing most usages of abstract classes today,
> providing much of the feature set asked for by "abstract enums" and
> effectively treating them as Java's traits. IMO, the addition of
> traits is as important to API design as lambdas themselves.
> What we need is a debate on the feature. Do we, as users/developers,
> want the minimal feature set necessary to support lambdas, or the
> maximal feature set that would occur were we adding traits to Java?
> Things that may be options with a fully implemented feature:
> - private-scoped methods
> - package-scoped methods (would probably require adding a package
> keyword for scope)
> - protected-scoped methods
> - static methods
> - what should the default scope be
> - whether the name "default interface" is the best choice ("trait interface"?)
> So, please chime in on whether you think default interfaces should be
> kept simple and minimal (as David suggested), or be thought of as a
> major new feature in their own right? (Try to initially focus on the
> big question without too much low-level detail)
More information about the lambda-dev