Re-specification and re-abstraction

Brian Goetz brian.goetz at oracle.com
Thu Dec 22 08:21:52 PST 2011


> Can a defaulted method invoke super.myMethod() (qualified by interface
> if needed)? If so, maybe another approach is to have redeclarations
> re-abstract by default, but allow them provide a default that calls a
> super's default if they're only desired as documentation.

Super-calls are supported (see the last page of the Featherweight 
Defenders doc for precise semantics), but they carry the same 
restriction that existing super-calls with classes do -- you can't "skip 
over" superclasses that provide a declarations.  So just as you can't 
super-call your way out of the following problem today:

class A {
     void m() { }
}

abstract class B extends A {
     abstract void m();
}

class C extends B {
     void m() { A.super.m(); } // illegal
}

we have the exact same restriction for interfaces (well, not exactly the 
same, since some doofus could try and cheat by inheriting A again.)  So 
an interface that extends a method with a reabstracted default can't 
super-call around the reabstraction any more than C can super-call 
around B's reabstraction in the above example.

For interface super-calls you have to specify which of your immediate 
superinterfaces you want to call through, since you could be overriding 
multiple methods at once:

interface I {
     void m() default ...;
}

interface J {
     void m() default ...;
}

interface K exends I, J {
     void m() default { I.super.m(); }  // OK
                                        // K.m overrides both I.m and J.m
}



More information about the lambda-dev mailing list