Syntax for calling super

"Zdeněk Troníček" tronicek at fit.cvut.cz
Thu Aug 23 13:38:51 PDT 2012


To use the same syntax for two conceptually different things is always
confusing. In this case, it is more confusing than what you describe on
K.default.
If I take into account that super.K.m() might be ambiguous (see below),
K.default is still my favourite.

interface K {
    void m() default { }
}


interface K2 {
    void m() default { }
}

class C1 {
    K K; // watch this!
}

class C2 extends C1 implements K, K2 {
    public void m() {
        super.K.m(); // what does this mean?
    }
}

Z.
-- 
Zdenek Tronicek
FIT CTU in Prague


Brian Goetz napsal(a):
> We already considered that one too.
>
> K.default would make sense *if* it were permitted for any class to just
> call directly to the default of any interface method, regardless of
> relationship in the hierarchy.  But instead we chose to follow the
> approach taken by classes; you can only super-call to a method if your
> class (is eligible to) directly override it; it is invisible to everyone
> else.  We chose semantics that are as similar to that as we could get;
> for that reason, we wanted a syntax that was similar too.
> "K.default.m()" seemed likely to surprise people when they found out
> they couldn't call the default for any old K.
>
> On 8/23/2012 1:46 AM, "Zdeněk Troníček" wrote:
>> In addition, K.super already means something else:
>>
>> class A {
>>      int x;
>> }
>>
>> class B extends A {
>>      int x;
>>      class B1 {
>>          int x;
>>          {
>>              System.out.println(B.super.x); // refers to A.x
>>              System.out.println(B.super.toString()); // calls
>> A.toString()
>>          }
>>      }
>> }
>>
>> What about K.default?
>>
>> Z.
>>
>



More information about the lambda-dev mailing list