Syntax for calling super

David Holmes david.holmes at oracle.com
Fri Aug 24 17:27:27 PDT 2012


On 25/08/2012 3:03 AM, GREGG WONDERLY wrote:
>
> On Aug 23, 2012, at 8:00 PM, David Holmes<david.holmes at oracle.com>  wrote:
>
>> 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.
>
> This view is troubling to me.  If we are in an inner class, and code
>
> OuterName.this.m();
>
> The compiler knows to look for the type OuterName in the hierarchy of class definitions visible to the inner class, and then invoke m().

I don't see OuterName as telling the compiler where to look for 
something, it is simply naming something. The current object is "this", 
the enclosing instance is OuterName.this. It is not a search path it is 
a direct name for an object.

> For default methods, if a we write
>
> OuterName.this.m();
>
> It seems to me that even though the compiler has to look in a slightly different way, the fully qualified name of OuterName is visible to it, so that it can ask "Is this a class" or "Is this an interface", and the take the appropriate steps to resolve what to invoke.

Here OuterName.this does not name an enclosing instance. You are using 
the same syntax for two completely different things in my view.

No doubt compiler writers and parser writes think about this 
differently, but from my perspective as an end-programmer, these are 
quite different things. If I was explaining what this statement meant to 
someone the explanation in the two cases would be completely different - 
hence in my opinion the same syntax should not be used for both.

David
-----

> Having the compiler do this small amount of introspection of the class/interface name space, seems like a lot better choice, then asking the developer to remember to type this vs super.
>
> What will be the compiler error message, if I type this instead of super or vice versa?  What will that do to help the developer really code effectively?
>
> Gregg


More information about the lambda-dev mailing list