Syntax for calling super

Peter Levart peter.levart at marand.si
Mon Aug 27 06:27:23 PDT 2012


On Monday, August 27, 2012 12:41:22 PM Peter Levart wrote:
> > K.super.m() already has an existing meaning with inner classes, just as 
> > K.this.m() does. There's a difference between searching for a type alone 
> > and searching for an object and then a type. Using the same notation is 
> > confusing in my view.
> 
> Oh, I wasn't aware of that. That changes things. In particular if there was
> a  situation where it could resolve to both (the super method of an outer
> instance and the particular super interface's default method). There would
> have to be a precendence rule or an unresolvable conflict which complicates
> things further.

And here it is (an example):

public interface J {
    void m() default {
       System.out.println("J: " + this);
    }
}

public interface K {
    void m() default {
       System.out.println("K: " + this);
    }
}

public class C implements J, K {
    @Override
    public void m() {
        new K() {
            @Override
            public void m() {
                K.super.m();
            }
        }.m();

        K.super.m();
    }

    public static void main(String[] args) {
        new C().m();
    }
}


... this example prints two different lines in the form:

K: C$1 at 65f9c5c8
K: C at 712801c5

Because K.super.m() is the same syntax used for two different things, I cannot 
call the same super method in inner class as I can directly in the body of 
C::k()...


Regards, Peter



More information about the lambda-dev mailing list