public class outerClass{
       InnerClass newClass = new InnerClass(){
         /*如果我在这里引用this指针,显然引用的是InnerClass的指针*/
         /*而我现在要在这里引用outerclass的this指针,我该如何操作呢?*/   
      } 
}class InnerClass(){
/*这里定义*/
}

解决方案 »

  1.   

    我刚才这样用的
    private static outerClass thisObj=this;
    然后outerClass.thisObj引用,这样竟然通不过,说是this非静态成员outerClass.this竟然成功,如果解释呢?this非静态成员,为什么可以outerClass.this这样使用呢?
      

  2.   

    private static outerClass thisObj=this
    这个时候 OuterClass 还没被实例化了
    而你在
      InnerClass newClass = new InnerClass(){
      /*如果我在这里引用this指针,显然引用的是InnerClass的指针*/
      /*而我现在要在这里引用outerclass的this指针,我该如何操作呢?*/   
      }
    这里用的时候,newClass 是OuterClass的一个普通成员,用newClass 的时候OuterClass 显然已经被实例化了
      

  3.   


    outerClass被实例化了吗,我怎么看不出来??
      

  4.   

    this指针实例化后实际就是指向实例,没实例化之前实际就是形式参数ClassPrototype * this,比如
    public class ClassPrototype{
           public void foo(){
             /*doSonmething();*/
           }
    }
    实际上就是
    public class ClassPrototype{
           public void foo(ClassPrototype *this){
             /*doSonmething();*/
           }
    }
    实例化后使用
    ClassPrototype ClassObj=new ClassPrototype();
                   ClassObj.foo();
    实际上就是ClassObj.foo((ClassPrototype *)&ClassObj);所以说this真的不是类得成员,更不是累的静态成员,为神马可以ClassPrototype.this这样使用,要说
    private static ClassPrototype thisObj=this;
    使用ClassPrototype.thisObjcai 才正确啊,但为啥结果反过来呢?
      

  5.   

    佐证:     假如this是类得成员变量,那么类得静态成员函数显然能够使用this,但是现在类得静态成员函数不能引用this,所以这更加说明this不是什么隐含的成员变量,它不过是个形式参数,隐含的,而且静态成员函数是没有的。
      

  6.   


    改为:
      假如this是类得静态成员变量,那么类得静态成员函数显然能够使用this,但是现在类得静态成员函数不能引用this,所以这至少说明this静态成员变量,因为静态成员函数只能使用static成员变量,而绝不能引用non-static成员变量,它不过是个形式参数,隐含的,而且静态成员函数是没有这个形式参数的。  不好有点偏题,但总的来说我还是想弄明白为什么可以ClassPrototype.this这样引用,我说前面那些话只是想知道ClassPrototype也就是类原型ClassPrototype.this这样引用,不是只能应用成员变量,而且必须是static的成员变量吗???