extension method implementations for methods of java.lang.Object
Jordan Stewart
jordan.r.stewart at gmail.com
Thu Aug 19 07:50:13 PDT 2010
It may be dodgy, but I don't think it's invalid code. The default equals
method declared in A should still apply in cases where equals is
reabstracted by a superclass.
E.g. if we extend your example with the following-
abstract class B {
abstract boolean equals(Object other);
}
class C extends B implements A {
// .equals -> As.eq
}
Or, even-
class D implements A {
// .equals -> Object.equals
}
abstract class E extends D {
abstract boolean equals(Object other);
}
class F extends E {
// .equals -> As.eq
}
On Fri, Aug 20, 2010 at 1:10 AM, Thomas Jung <
thomas.andreas.jung at googlemail.com> wrote:
> That's okay.
>
> Then the compiler should print a warning that this default method
> definition will never apply as all reference types extend
> java.lang.Object and the set of problematic methods signatures is
> (practically) fixed and known. It could even be considered invalid
> code.
>
> Thomas
>
> On 19 August 2010 15:04, Brian Goetz <brian.goetz at oracle.com> wrote:
> > That is correct, and does not bother me. The goal of extension methods
> did
> > not include being able to reabstract existing concrete methods from
> Object.
> > We're not trying to solve all the problems of the world in one go...
> >
> > On 8/19/2010 3:59 AM, Thomas Jung wrote:
> >>
> >> Hi,
> >>
> >> with the current prototype it's not possible to define a default
> >> implementation for Object#equals.
> >>
> >> interface A{
> >> extension boolean xequals(Object obj) default As.eq;
> >> extension boolean equals(Object obj) default As.eq;
> >> }
> >>
> >> static class As{
> >> public static boolean eq(A me, Object object){
> >> throw new RuntimeException();
> >> }
> >> }
> >>
> >> a.equals(new Object()); //passes
> >> a.xequals(new Object()); //throws exception
> >>
> >> This feature is useful if the equals implementation for some subtypes
> >> of A can be expressed based on the methods defined in A.
> >>
> >> Thomas
> >>
> >
>
>
More information about the lambda-dev
mailing list