Syntax for calling super

Brenden Towey brendentowey at gmail.com
Wed Aug 22 18:35:38 PDT 2012


True.  In that case, I think I prefer your suggestion, super.K.m().

K.super.m() seems to be invoking the super-class of K, not of J. It's a 
little confusing.  super.K.m() reads a bit more clearly. "my super 
class" . "oh, this interface K though" . "m()"

I can see a case for a cast, but super.K.m() is a convenient shorthand.  
Less typing (and less reading!) is sometimes the better option.  
Something like ((K) super).m() is a bit unnecessarily long.


On 8/22/2012 6:28 PM, David Holmes wrote:
> On 23/08/2012 11:09 AM, Brenden Towey wrote:
>> On 8/22/2012 3:32 PM, Yuval Shavit wrote:
>>> To my mind, the syntax "should" be K.m() (without the super). That 
>>> makes
>>
>>
>> I'd tend to agree, except for the problems you mention.  What about
>> "J.super.m()"?  "Don't call me call my parent class?"
>>
>> interface J extends K {
>>      int m() default { return J.super.m(); }  // calls J's parent's m()
>> }
>
> The problem with that is that you need to be able to select from 
> multiple parents, so the parent's type has to be in there somewhere.
>
> David



More information about the lambda-dev mailing list