LoginSignup
0

More than 5 years have passed since last update.

Java: インナークラスを外で継承し、コンストラクタ内でenclosing instanceをnew

Last updated at Posted at 2012-09-08

こんなことができるのか… org.eclipse.jdt.core.tests.compiler.regression.InnerEmulationTest.test090 より:

D.java
public class D {
  public void main(String[] args) {
    class Middle {
      class Inner {}
    }
    class M extends Middle.Inner {
      M() { new Middle().super(); } // !!!
    }
    new M();
  }
}

インナークラスを外で継承して、コンストラクタの中で(!) enclosing class のインスタンスを生成するという方法。
昨日のポストにかなり関係していそう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0