Java, generally speaking this pointer refers to the object of this code that is currently being accessed, but if you need to use an object in an external class in an inner class, you need to qualify with the class name of the outer class. This approach is also more common in Android development.
@Author: Twlkyao
package Twlkyao;
public Class A {public
a () {
Inner Inner = new Inner ();
Inner.outer (); Call the inner class ' s outer method.
This.outer (); Call A ' s outer method.
}
public void outer () {
System.out.println ("outer run");
}
Class Inner {public
void outer () {
System.out.println ("Inner Run");
A.this.outer (); Call A ' s outer method.
System.out.println ("--------");
}
public static void Main (string[] args) {
A A = new A ();
}
}
Inner is an inner class that accesses the outer () method in Class A and, because of the same method in the anonymous inner class, needs to be qualified with the this pointer of a.
The output results are:
Inner run
outer run
--------
outer Run