Hi everyone !
We know that it is not allowed. My question is - why ?
Is it because nested classes are tied to outer classes,
so we could actually think of nested classes as "separate"
or "different" classes for each different instance of the
outer class ? What I mean is if we have two different outer
objects, then we could follow two logics here:
Outer o1; Outer o2;
1) Outer.Inner.x=10; => o1.Inner.x==o2.Inner.x
2) or perhaps Outer.Inner.x should be not allowed
and the only way to access x would be o1.Inner.x
and o2.Inner.x and o1.Inner.x should be != o2.Inner.x ?
The first one seems to be easier to understand and potentially
to implement it (in the javac and/or JVM). But since there is already
that kind of semantics (static inner classes), and this is
that kind of inner class which is binded to outer class,
the second one might be the "better" attempt. And that
could possibly cause a lot of troubles in implementing
it as a new
java feature and finally would be the answer to
my question why it is not allowed.
Please note, that it is allowed to have a static member
field which is declared final - why ?
However - which is even more strange to me - it is allowed
to define a nested class which extends class which has
static members, so implicitly the new defined nested class
HAS static members ...
Could anybody put some light on that topic please ?
And as a bonus
- why inner classes defined inside
interfaces are implicitly static ?
Cheers,
Adrian