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()
That would be perfectly all right, if you get your thrills
from reading the compiler's error messages. :)
does it have anything do with the fact that this line is found within an anonymous inner class that is an actionListener?
Yes. An unadorned `this' would refer to the instance of the
class whose code is running. That's the anonymous class that
implements ActionListener, a class that doesn't even *have* a
dispose() method (unless one's been added explicitly in the
anonymous class, which would be awfully strange).
Writing `this.dispose()' or simply `dispose()' would try
to call the anonymous class' dispose() method, not any method
belonging to the enclosing myDialog (poor choice of name, BTW).
The intent, most likely, is to close the dialog -- so the code
uses `myDialog.this' to mean "Not *this* `this', but the `this'
of the enclosing class named `myDialog'." It's that enclosing
class' dispose() that's being called.
--
Eric Sosman
esosman@comcast-dot-net.invalid