Syntax for calling super
Howard Lovatt
howard.lovatt at gmail.com
Tue Aug 28 00:48:56 PDT 2012
I am on Brian's side with this. The use case of wanting inner classes that
access their super and interfaces with defaults is very obscure. More
likely you will start with inner classes:
class OuterOuterSuper {
String level() { return "Outer Outer Super"; }
}
class OuterSuper {
String level() { return "Outer Super"; }
}
class InnerSuper {
String level() { return "Inner Super"; }
}
public class OuterOuter extends OuterOuterSuper {
String level() { return "Outer Outer"; }
class Outer extends OuterSuper {
String level() { return "Outer"; }
class Inner extends InnerSuper {
String level() { return "Inner"; }
void print() {
out.println(level());
out.println(super.level());
out.println(Outer.super.level());
out.println(OuterOuter.super.level());
}
}
}
}
And convert to interfaces that have a flat structure because the original
nesting was simply to enable multiple inheritance:
interface I1 {
String level() { return "I1"; }
}
interface I2 {
String level() { return "I2"; }
}
interface I3 {
String level() { return "I3"; }
}
class Inner implements I1, I2, I3 {
String level() { return "Inner"; }
void print() {
out.println(level());
out.println(I1.super.level());
out.println(I2.super.level());
out.println(I3.super.level());
}
}
(Apologies in advance if the above is not the latest syntax.)
This seems like a natural transition to me from nested classes to flat
interfaces. Therefore I think the syntax is the correct choice and the
situation of wanting to access the super of an inner class and its super
interface default method will be so rare that it can be ignored at this
stage. If there are any use cases something can be added in 9.
-- Howard.
On 28 August 2012 17:12, Peter Levart <peter.levart at marand.si> wrote:
> On Monday, August 27, 2012 10:17:45 AM Gregg Wonderly wrote:
> > On Aug 27, 2012, at 8:27 AM, Peter Levart <peter.levart at marand.si>
> wrote:
> > > On Monday, August 27, 2012 12:41:22 PM Peter Levart wrote:
> > >>> 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.
> > >
> > > And here it is (an example):
> > >
> > > public interface J {
> > >
> > > void m() default {
> > >
> > > System.out.println("J: " + this);
> > >
> > > }
> > >
> > > }
> > >
> > > public interface K {
> > >
> > > void m() default {
> > >
> > > System.out.println("K: " + this);
> > >
> > > }
> > >
> > > }
> > >
> > > public class C implements J, K {
> > >
> > > @Override
> > > public void m() {
> > >
> > > new K() {
> > >
> > > @Override
> > > public void m() {
> > >
> > > K.super.m();
> > >
> > > }
> > >
> > > }.m();
> > >
> > > K.super.m();
> > >
> > > }
> > >
> > > public static void main(String[] args) {
> > >
> > > new C().m();
> > >
> > > }
> > >
> > > }
> > >
> > >
> > > ... this example prints two different lines in the form:
> > >
> > > K: C$1 at 65f9c5c8
> > > K: C at 712801c5
> > >
> > > Because K.super.m() is the same syntax used for two different things, I
> > > cannot call the same super method in inner class as I can directly in
> the
> > > body of C::k()…
> >
> > I think I am lost in what is trying to be "proven" in these discussions.
> > Peter, are you trying to say that K.super.m() will change what is
> resolved
> > when used with default methods, or are you saying that there is a
> > particular namespace that you can not reach? Or, is thee something else
> > here that I can't see because of my focus?
>
> I was trying to say that there is no way to call the super interface
> method of
> an outer instance when the same member or interface_name/member also
> exists in
> the inner class's superinterface, because there is no way to explicitly
> specify the outer instance. More about that has been clarified in later
> posts.
>
> Regards, Peter
>
>
> >
> > Gregg
>
>
--
-- Howard.
More information about the lambda-dev
mailing list