Superinterface.this.method()
maurizio cimadamore
maurizio.cimadamore at oracle.com
Sun Dec 18 04:00:39 PST 2011
On 18-Dec-11 3:12 AM, bitter_fox wrote:
> interface A
> {
> public void a() default
> {
> System.out.println("A");
> }
> }
>
> class B implements A
> {
> public void a()
> {
> A.this.a(); // "A" or StackOverflowError?
> }
> }
Hi
The syntax for A.this.a() should be disallowed, as, according to the
JLS, A should be an enclosing class (which is not the case here). I
think it's reasonable to expect that the final version of the compiler
would give an error similar to the one you get today with JDK 5/6/7 if
you remove the default from A and you make B abstract - the compiler
will complain because 'A is not an enclosing class'.
What you want here is:
A.super.a()
as described in the latest State of the Lambda draft [1].
The semantics of A.this/A.super where A is an interface with extension
methods is still to be correctly implemented by the compiler - so I
wouldn't rely much on what is/isn't accepted by the compiler as of today.
Thanks
Maurizio
[1] - http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html
More information about the lambda-dev
mailing list