Originally posted by Amit Saini:
Hi,
Think of "static" keyword as "one per class".
That's misleading and not helpful, because the keyword static is actually
working overtime, when it is allowed to modify member classes:
Instances of class B have an implicitly defined field T.this of type T that
refers to the enclosing object. The println statement in b is short for:
System.out.println(T.this.t);
Because of the static keyword, instances of class C do not have an inplicitly
defined field T.this, so the same println statement causes the compile-time
error message listed above.
But you can have as many instance of C as you like: static does not imply
"one per class" -- you can call the newC method multiple times; rather
static implies, as the JLS puts it in 8.5.2:
Just as a static method of T has no current instance of T in its body,
C also has no current instance of T, nor does it have an lexically enclosed
instances.