Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22658
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: quick question |
| Date | 2013-03-01 20:08 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <kgqu9s$2hd$1@dont-email.me> (permalink) |
| References | <23b84c9f-ada5-4d99-9aa5-d291dd14b312@googlegroups.com> <kgqt33$s5k$1@dont-email.me> |
On 01/03/2013 19:48, Eric Sosman allegedly wrote: > 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. > For the record, it's called a "Qualified 'this'", and the specification can be found here: <http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.8.4> -- DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
quick question Doug Mika <dougmmika@gmail.com> - 2013-03-01 10:25 -0800
Re: quick question Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-01 13:48 -0500
Re: quick question Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-03-01 20:08 +0100
Re: quick question Donkey Hottie <donkey@fredriksson.dy.fi> - 2013-03-01 22:52 +0200
Re: quick question Joerg Meier <joergmmeier@arcor.de> - 2013-03-01 22:22 +0100
Re: quick question Lew <lewbloch@gmail.com> - 2013-03-01 15:31 -0800
Re: quick question Arne Vajhøj <arne@vajhoej.dk> - 2013-03-01 18:30 -0500
Re: quick question Roedy Green <see_website@mindprod.com.invalid> - 2013-03-01 15:38 -0800
csiph-web