Syntax for calling super

Gregg Wonderly gregg at wonderly.org
Mon Aug 27 08:17:45 PDT 2012


On Aug 27, 2012, at 8:27 AM, Peter Levart <peter.levart at marand.si> wrote:

> 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()…

I think I am lost in what is trying to be "proven" in these discussions.  Peter, are you trying to say that K.super.m() will change what is resolved when used with default methods, or are you saying that there is a particular namespace that you can not reach?  Or, is thee something else here that I can't see because of my focus?

Gregg


More information about the lambda-dev mailing list