Syntax for calling super

David Holmes david.holmes at oracle.com
Thu Aug 23 18:00:03 PDT 2012


On 24/08/2012 12:56 AM, Peter Levart wrote:
> On Thursday, August 23, 2012 11:01:46 AM David Holmes wrote:
>> On 23/08/2012 8:13 AM, Brian Goetz wrote:
>>> The syntax was designed to be analogous to the "K.this.m()" syntax that
>>> is used in inner classes.
>>
>> But the semantics are quite different. K.this is a reference to a
>> completely different object (the enclosing instance from class K).
>> Whereas as K.super is meant to infer something about 'this'.
>
> Intuitively I don't have problems with K.super. I see K.something as something
> qualified with type K.
>
> In case of "this" it selects the innermost instance of type K, whereas in case
> of "super" it selects the most specific visible member from the
> superclass/superinterface K's hierarchy.
>
> In both cases K is an addidional restriction to the "search strategy".

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.

As Zdenek points out super.K.m() has an ambiguity problem that I had 
overlooked.

So every proposal has its problems unfortunately.

What about a simple method reference K::m() ? With a rule that says that 
it is only accessible if K is a direct superinterface?

David

> Regards, Peter
>
>>
>> If anything I think super.K.m() is more natural as an extension to the
>> existing super.m() notation.
>>
>> David
>> -----
>>
>>> One problem with the syntax you suggest is that unlike "this", "super"
>>> is not a valid expression.
>>>
>>> This would be made worse by the inconsistency it would introduce over
>>> "this"; currently ((K) this) has a meaning, and the role of casting to
>>> an enclosing (K) in that meaning would not be consistent with your
>>> suggestion for ((K) super).
>>>
>>> That said, we're not married to the K.super.m() syntax if there is an
>>> obviously better one.  On the other hand, we don't dislike the
>>> K.super.m() syntax either.
>>>
>>> On 8/22/2012 5:41 PM, Paul Benedict wrote:
>>>> This syntax caught my eye:
>>>>
>>>> interface K {
>>>>
>>>>      int m() default { return 88; }
>>>>
>>>> }
>>>>
>>>> interface J extends K {
>>>>
>>>>      int m() default { return K.super.m(); }
>>>>
>>>> }
>>>>
>>>> I really don't think it is is appropriate to code "K.super.m()". An
>>>> natural English reading of "K.super" would be "superclass of K" since
>>>> it is K that is qualified.... but that's not what the code intends to
>>>> be.
>>>>
>>>> I would recommend a casting syntax to make the intention clearer:
>>>> interface J extends K {
>>>>
>>>>      int m() default { return ((K) super).m(); }
>>>>
>>>> }
>>>>
>>>> Paul
>


More information about the lambda-dev mailing list