Syntax for calling super

Peter Levart peter.levart at
Mon Aug 27 03:41:22 PDT 2012

On Friday, August 24, 2012 11:00:03 AM David Holmes wrote:
> > 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.

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.

Also the question remains about the syntax of calling the particular 
superinterface's (K's) default method from an inner class of an Outer class 
implementing the interface? Outer.K.super() or K.Outer.super() ? Isn't that 
ambigous too?

Somewhere in another message you mentioned that K.super.m() in an inner class 
could be viewed as a shorthand for K.this.super.m(). Now if the later syntax 
was realy a legal syntax and K.super.m() just a shorthand for it, then:


would actualy be a shorthand for:


To select a particular interface's default method you could then cast "this" 
to it's type:

((K) this).super.m();

Compiler would have to prove that the expression before .super.m() (the 
receiver) actualy is "this" (could also be an Outer.this) and the type of the 
expression is one of the "direct" supertypes of the class in context.

To call  the particular superinterface's (K's) default method from an inner 
class of an Outer class implementing the interface, you could use:

((K) Outer.this).super.m();



> 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

More information about the lambda-dev mailing list