In Java, is it possible that calling the super constructor invokes the constructor in the calling class?

Super constructor call definition :

[Primary.] [NonWildTypeArguments] super ( ArgumentListopt ) ;

A superconstructor call can be prefixed with an expression Primary. Example (taken from JLS):

class Outer {
    class Inner{ }
}

class ChildOfInner extends Outer.Inner {
    ChildOfInner() {
        (new Outer()).super(); // (new Outer()) is the Primary
    }
}

Is there an expression Primarythat makes a call to super () a call to the constructor of the calling class? Or does Java prevent this?

+3
source share
2 answers

Is there a primary expression that makes a call to super () a call to the constructor of the calling class?

. super(), this(). Primary , .

- , (.. , ).

Edit:

OP . - , , , :

... super... .

, p, ".super", ... [] ... , p O [ ] O.

super , ( ). , super(), , , , super() - super() .

+2
0

Source: https://habr.com/ru/post/1784285/


All Articles