Originally posted by Gene Chao:
We know that the following compiles fine.
Now, right below line 2, I instantiate an Outer and try to use it inside doStuff() like so:
Outer outer = new Outer(); // 3
System.out.println("outer instance reference is: " + outer.this); // 4.
Line 4 won't compile, javac says that it cannot resolve the symbol outer. If we modify Line 4 by removing ".this" like
System.out.println("outer instance reference is: " + outer);
then it compiles and runs OK.
So, does this mean that we can only do OuterClassName.this, but not outerClassInstance.this in the inner class? Or does outerClassInstance.this in an inner class not make sense?
Thanks a lot
Gene
====================================================================
I think we can do only outerclassname.this but not outerclassinstance.this.
cz outerclassname.this evaluates to a reference that denotes the enclosing object of the current instance of a non-static inner class.