应该是class inner 的句柄,因为只是扩展内部类,而不是内部类

解决方案 »

  1.   

    class WithInner{ 
    WithInner() {System.out.println("withInner");}
        class Inner{
         Inner() {System.out.println("Inner");}
        } 

    class InheritInner extends WithInner.Inner 

    InheritInner(WithInner wi) { 
    wi.super();
    System.out.println("InheritInner");
    } //请问wi.super()怎么理解

    public class q{     
        public static void main(String[] args){ 
            WithInner wi = new WithInner(); 
            System.out.println("XXXXXXXXXXXXX");
            InheritInner ii = new InheritInner(wi); 
        } 

    /*****************************************************************************/
    Console:withInner
    XXXXXXXXXXXXX
    Inner
    InheritInner---------------------------------------------------------------------------
    super:子类继承父类的构造方法时,子类如果使用父类的构造方法必须在子类的构造方法中用super关键字.这里的super这是调用InheritInner 父类的构造方法.只不过Inner 是WithInner的内隐类.所以用WithInner的对象来调用super
      

  2.   

    我明白了,就是不能直接使用new Inner()来创建一个新的类,而应通过wi.Inner()来创建一个Inner类的实例对象;所以在楼主的例子中,super之前需要使用wi.super();,其实调用的还是InheritInner它自己的父类。呵呵。学到了。
      

  3.   

    原来是tij的一个例子,这么做是为了获得宿主对象的reference来初始化内部类,但.super的语法的确比较怪:Because the inner class constructor must attach to a reference of the enclosing class object, things are slightly complicated when you inherit from an inner class. The problem is that the “secret” reference to the enclosing class object must be initialized, and yet in the derived class there’s no longer a default object to attach to. The answer is to use a syntax provided to make the association explicit: Feedback
    //: c08:InheritInner.java
    // Inheriting an inner class.class WithInner {
      class Inner {}
    }public class InheritInner extends WithInner.Inner {
      //! InheritInner() {} // Won't compile
      InheritInner(WithInner wi) {
        wi.super();
      }
      public static void main(String[] args) {
        WithInner wi = new WithInner();
        InheritInner ii = new InheritInner(wi);
      }
    } ///:~You can see that InheritInner is extending only the inner class, not the outer one. But when it comes time to create a constructor, the default one is no good, and you can’t just pass a reference to an enclosing object. In addition, you must use the syntax Feedback
    enclosingClassReference.super();inside the constructor. This provides the necessary reference, and the program will then compile. Feedback