Syntax for calling super

Yuval Shavit yshavit at akiban.com
Wed Aug 22 15:32:54 PDT 2012


Fwiw, I instantly saw the parallel to K.this.m() when I saw K.super.m().
It's not an exact metaphor, but close enough that I got it. That said, I
think K.this.m() is probably considered obscureish, in that you only need
it in some edge cases. I'd expect that K.super.m() will be similar in its
edgy-ness.

To my mind, the syntax "should" be K.m() (without the super). That makes
sense to me because it's saying "use K's version of m()," but it's bad in
that it looks like K.m is a static class (and perhaps more significantly,
will be ambiguous should interfaces ever get static methods). So, I think
K.super.m() is a good mix -- it's about the best I could imagine in a
language where instance methods are always virtual. I read it as "treat
'this' as one of its super-classes, specifically K, when you invoke m."

On Wed, Aug 22, 2012 at 6:13 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

> The syntax was designed to be analogous to the "K.this.m()" syntax that
> is used in inner classes.
>
> 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