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


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

Re: A small exercise

Date 2013-04-28 10:37 +0100
From lipska the kat <"nospam at neversurrender dot co dot uk">
Organization Trollbusters 3
Newsgroups comp.lang.java.programmer
Subject Re: A small exercise
References <exercise-20130420150736@ram.dialup.fu-berlin.de> <R_2dnU9jtOi9Ie_MnZ2dnUVZ7q-dnZ2d@bt.com> <au2n7aF1rgnU1@mid.dfncis.de>
Message-ID <ALmdnZhOX5pKcOHMnZ2dnUVZ8uydnZ2d@bt.com> (permalink)

Show all headers | View raw


On 27/04/13 20:28, Sven Köhler wrote:
> Am 20.04.2013 19:02, schrieb lipska the kat:
>> I think that logically, Main.this.b refers to the enclosing *instance*
>> which implies that the class has been instantiated
>
> "this" also refers to an instance - doesn't it?
> And following your argument, I should not be able to use "this" in the
> constructor.
>
> I'm not saying, that the JLS makes a different between a mere "this" and
> a construct of the form "Classname.this" and that this is essentially
> the cause for the code not compiling. But I don't see the point of your
> argument.

java-7-openjdk, Eclipse Juno

this compiles

final int a; int b;
	
public Main(){
    this.a = 0;
    Main.this.b = 0;
}

this doesn't

final int a; *final* int b;
	
public Main(){
    this.a = 0;
    Main.this.b = 0;
}

The only difference is the final modifier applied
to the second b

I suppose I agree that at first site this and Main.this refer to the 
same instance, however we are still left with the fact the second 
snippet doesn't compile. So, I'm saying that *logically* this and 
Main.this are not equivalent. If they were then we wouldn't be having 
this problem would we?

Or maybe you know better, in which case can you tell me 'cause this is 
starting to bug me.

Now I'm trying to figure out *why* they are different and one theory is 
that as far as the complier is concerned the construct Main.this.b in 
some way *implies* that Main has already been instantiated so attempting 
to initialize a final variable after instantiation is illegal.

Does that make more sense?

No!, well do you have a better idea?

Interesting discussion

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


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