Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22658

Re: quick question

Path csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: quick question
Date Fri, 01 Mar 2013 20:08:56 +0100
Organization A noiseless patient Spider
Lines 39
Message-ID <kgqu9s$2hd$1@dont-email.me> (permalink)
References <23b84c9f-ada5-4d99-9aa5-d291dd14b312@googlegroups.com> <kgqt33$s5k$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Date Fri, 1 Mar 2013 19:07:40 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="e78636ce44bf9dbba8b3342c71ac6a05"; logging-data="2605"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1954hvkAk6p3Kp7nLhgVoRC"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
In-Reply-To <kgqt33$s5k$1@dont-email.me>
Cancel-Lock sha1:Q5ORHpzo5EsHqaaTQ8k8QmlQXDo=
Xref csiph.com comp.lang.java.programmer:22658

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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