Preparing for the 0.2 draft
Osvaldo Doederlein
opinali at gmail.com
Sat Jan 30 11:17:55 PST 2010
2010/1/30 Rémi Forax <forax at univ-mlv.fr>
> Le 30/01/2010 14:38, Mark Thornton a écrit :
> > Osvaldo Doederlein wrote:
> >> 2010/1/30 Fredrik Öhrström<fredrik.ohrstrom at oracle.com>
> >>> Just because every piece of code in Java you have written so far, has
> >>> been a method inside an object
> >> Well, there is the enormous exception of all Java code inside static
> >> methods, static initializers, and field-initializing expressions. (The
> >> latter _is_ "code inside an object" because it's compiled into
> constructors;
> >> but you can't use 'this' anyway.)
> >>
> > public class Init
> > {
> > private Init me = this;
> > }
> >
> > Is legal. It is static contexts and the arguments of super that can't
> > contain this (as far as I can recall).
>
Thanks for the correction. It's amazing that I could use Java since 1.0-beta
without ever noticing that 'this' was valid in instance variable
initializers. But yeah, it makes sense, since I could (and ofteh do) write
initializers like "var2 = var1", which is shorthand for "var2 = this.var1".
(And teaches me the lesson of not guessing the grammar from experience
instead of looking up the JLS.)
A+
Osvaldo
> >
>
> It's an instance variable initializer (words from the JLS), it's not a
> static context.
>
> > Mark
> >
>
> Rémi
>
>
>
More information about the lambda-dev
mailing list