posted 20 years ago
Here is my own way of thinking about this subject. However, I cannot back this up with the JLS. It�s just the way I have organized these ideas in my head.
We start by specifying a fully qualified name. You cannot go wrong (usually) with a fully qualified name.
new A.B()
new A.C()
But if you are inside the class A, you don�t have to qualify the name, although you can if you want to (usually).
new B()
new C()
However, don�t forget that an instance of a non-static member class B has a reference to an instance of the enclosing class A.
So when you are in a static context, you must specify the instance of the enclosing class. Or if you want to specify some instance other than the current object �this�.
new A().new B()
a.new B()
You cannot do the following, I suppose because you would be specifying two type names for the enclosing class.
new A().new A.B() // error
a.new A.B() // error
And you cannot do the following, I can only guess because the outer object is not needed, it serves no purpose.
new A().new C() //error, static member class
a.new C() // error static member class