Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23691
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| References | (2 earlier) <5172e967$0$32109$14726298@news.sunsite.dk> <LvqdnUgkK5sPJO7MnZ2dnUVZ7oydnZ2d@bt.com> <517b3461$0$32112$14726298@news.sunsite.dk> <2rWdnWTV7bz8FubMnZ2dnUVZ7qGdnZ2d@bt.com> <517c8241$0$32104$14726298@news.sunsite.dk> |
| Subject | Re: A small exercise |
| Date | 2013-04-28 11:34 +0100 |
| Message-ID | <2fednevwr_TPZuHMnZ2dnUVZ8uCdnZ2d@bt.com> (permalink) |
Arne Vajhøj wrote:
> On 4/27/2013 4:25 AM, lipska the kat wrote:
> > This *implies* to me that this.b and Main.this.b are not *logically
> > equivalent*, this is what I said, nothing to do with whether
> > [obnoxious stuff elided]
>
> Nope.
>
> The JVM agrees.
>
> Try:
>
> System.out.println(this==Main.this);
But that proves nothing, doesn't even indicate anything. It's commonplace for
two independent identifiers to refer to the same object. And those two
different forms of reference may have different rules (consider using protected
access via "this" verses an independent reference to the same object). Lipska
is suggesting that this is one of those occasions, and that's a perfectly
plausible hypothesis.
I don't think it turns out to be true, though -- the JSL3 seems to be in
opposition. A trawl through the spec (my first in years) discovers 15.8.4,
quoted in toto (with the usual bloody difficulty):
15.8.4 Qualifed this
Any lexically enclosing instance can be referred to by explicitly qualifying
the keyword this.
Let C be the class denoted by <ClassName>. Let n be an integer such that C
is the nth lexically enclosing class of the class in which the qualified
[this] expression appears.The value of an expression of the form
<ClassName>.[this] is the nth lexi cally enclosing instance of [this].
(8.1.3).
The type of the expression is C.It is a compile-time error if the current
class
is not an inner class of class C or C itself.
(my <>s and []s)
The last three words seem, if not decisive, then at least strongly indicative
to me.
I'm guessing (and I admit that I can find no other supporting evidence) that
this is a bug in the compiler where code that is written on the assumption that
"C" above must be a strictly enclosing class. In those case the (equivalent)
code would obviously be incorrect (and that goes for the blank-final example
too). In particular I suspect that its something going squiffy in the
contorted logic that allows nested classes to refer to private fields of the
[not actually] "enclosing" class at runtime: that horrible stuff that is added
to circumvent the JVMs own checking.
But I may as well admit that one piece of evidence against my guess is that
both javac and Eclipse "fail" in the same way.
-- chris
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-20 17:02 +0100
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-20 15:15 -0400
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-21 11:04 +0100
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-26 22:13 -0400
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-27 09:25 +0100
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-27 21:58 -0400
Re: A small exercise "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-04-28 11:34 +0100
Re: A small exercise Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-28 12:17 +0000
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-28 14:05 +0100
Re: A small exercise Sven Köhler <remove-sven.koehler@gmail.com> - 2013-04-28 16:14 +0300
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-28 14:54 +0100
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-28 09:57 -0400
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-28 10:14 -0400
Re: A small exercise Sven Köhler <remove-sven.koehler@gmail.com> - 2013-04-27 22:28 +0300
Re: A small exercise markspace <markspace@nospam.nospam> - 2013-04-27 13:53 -0700
Re: A small exercise Arne Vajhøj <arne@vajhoej.dk> - 2013-04-27 21:44 -0400
Re: A small exercise lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-28 10:37 +0100
csiph-web