Defender Extension Methods -- Resolution and Invoccation
Brian Goetz
brian.goetz at oracle.com
Thu Aug 5 06:36:06 PDT 2010
> I know I've voiced this before but I'm not a fan of defender methods. I
> just don't see how this is not already multiple inheritance.
Java has always had multiple inheritance of types, through interfaces. (And
since 1.1 Java has had multiple inheritance of behavior in the context of
inner classes; members of both the lexical scope and the inner class hierarchy
are in scope inside an inner class.)
Multiple inheritance per se is not evil; we've been enjoying it for years.
The real pain of multiple inheritance is when it comes to *state* (as with so
many things). Defender methods do not introduce state in interfaces.
Defender methods are clearly a point on the spectrum somewhere between the
current state of Java and C++.
Note also that it is not as far along this spectrum as mixins or traits. Some
have advocated we should do mixins or traits or... Because defender methods
is a more measured solution that meets the current goal (be able to add
lambdaphilic methods to interfaces like Collection.filter), this solution is
preferred to those other solutions.
More information about the lambda-dev
mailing list