Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22656 > unrolled thread
| Started by | Doug Mika <dougmmika@gmail.com> |
|---|---|
| First post | 2013-03-01 10:25 -0800 |
| Last post | 2013-03-01 15:38 -0800 |
| Articles | 8 — 8 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Doug Mika <dougmmika@gmail.com> |
|---|---|
| Date | 2013-03-01 10:25 -0800 |
| Subject | quick question |
| Message-ID | <23b84c9f-ada5-4d99-9aa5-d291dd14b312@googlegroups.com> |
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? Thanks Mika
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-03-01 13:48 -0500 |
| Message-ID | <kgqt33$s5k$1@dont-email.me> |
| In reply to | #22656 |
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
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2013-03-01 20:08 +0100 |
| Message-ID | <kgqu9s$2hd$1@dont-email.me> |
| In reply to | #22657 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Donkey Hottie <donkey@fredriksson.dy.fi> |
|---|---|
| Date | 2013-03-01 22:52 +0200 |
| Message-ID | <r1h70a-619.ln1@tempest.fredriksson.dy.fi> |
| In reply to | #22658 |
01.03.2013 21:08, Daniele Futtorovic kirjoitti:
> 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>
>
This "Qualified this" is kind of hard to understand. How
myDialog.this.dispose()
differs from
myDialog.dispose()
If myDialog is an object instance, would't it be sufficient just call
dispose it?
--
"Unfortunately suspend does mean things sometimes"
Husse Apr 25 2007
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2013-03-01 22:22 +0100 |
| Message-ID | <1byh8mg13cq75$.4c0hmlfvk5t8$.dlg@40tude.net> |
| In reply to | #22662 |
On Fri, 01 Mar 2013 22:52:42 +0200, Donkey Hottie wrote: > This "Qualified this" is kind of hard to understand. How > myDialog.this.dispose() > differs from > myDialog.dispose() > If myDialog is an object instance, would't it be sufficient just call > dispose it? Despite the ill chosen name, myDialog is a class name, not an object instance: > 01.03.2013 21:08, Daniele Futtorovic kirjoitti: >> 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 Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2013-03-01 15:31 -0800 |
| Message-ID | <098e9b67-c944-4be5-adf7-8b91da09257c@googlegroups.com> |
| In reply to | #22663 |
Joerg Meier wrote: > Donkey Hottie wrote: >> This "Qualified this" is kind of hard to understand. How >> myDialog.this.dispose() >> differs from >> myDialog.dispose() > >> If myDialog is an object instance [sic], would't it be sufficient just [to] call >> dispose [on] it? If it were an instance reference, it wouldn't be the enclosing instance. > Despite the ill chosen name, myDialog is a class name, not an object > instance: -- Lew
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-03-01 18:30 -0500 |
| Message-ID | <513139fa$0$281$14726298@news.sunsite.dk> |
| In reply to | #22656 |
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
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2013-03-01 15:38 -0800 |
| Message-ID | <pue2j81og0r8kr3qji393p466diio663c1@4ax.com> |
| In reply to | #22656 |
On Fri, 1 Mar 2013 10:25:18 -0800 (PST), Doug Mika <dougmmika@gmail.com> wrote, quoted or indirectly quoted someone who said : >does it have anything do with the fact that this line >is found within an anonymous inner class that is an actionListener? Inside the anonymous class "this" refers to the dependent anonymous class object. by prefixing the class you get the outer object. -- Roedy Green Canadian Mind Products http://mindprod.com One thing I love about having a website, is that when I complain about something, I only have to do it once. It saves me endless hours of grumbling.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web