Re: quick question
On 3/1/2013 1:25 PM, Doug Mika wrote:
reading a book a came upon the following inside a 'myDialog extends
JDialog" class inside an actionlistener implemented as an anonymous
inner class.
myDialog.this.dispose()
why not simply write
this.dispose()
does it have anything do with the fact that this line is found within
an anonymous inner class that is an actionListener?
Other have already explained the difference between the two lines.
Two examples to supplement:
ThisFun1:
public class ThisFun1 {
public static void main(String[] args) {
A a = new A();
A.B b = a.new B();
A.B.C c = b.new C();
c.demo();
}
}
class A {
public void dump() {
System.out.println("I am A");
}
class B {
public void dump() {
System.out.println("I am B");
}
class C {
public void dump() {
System.out.println("I am C");
}
public void demo() {
dump();
this.dump();
C.this.dump();
B.this.dump();
A.this.dump();
}
}
}
}
ThisFun2:
public class ThisFun2 {
public static void main(String[] args) {
X x = new X();
x.demo();
}
}
class X {
public void dump() {
System.out.println("I am X");
}
public void demo() {
call(new Y() {
public void m() {
dump();
this.dump();
X.this.dump();
}
});
}
public void call(Y y) {
y.m();
}
}
abstract class Y {
public abstract void m();
public void dump() {
System.out.println("I am Y");
}
}
Arne