Originally posted by madhur jain:
hi!
but then we should be able to access it like
new Outer().NonStaticInner.e);
but this gives error
instead this works.
new Outer().new NonStaticInner().e);
why!
madhur.
Yes, the first syntax example does not work but the second one does. It is necessary to create an instance of the NonStaticInner class before attempting to access any member of the class.
Since the constant value that you are attempting to access does exist at compile time it would have been possible to design the language such that the compile time constant can be accessed without first creating an instance of the NonStaticInner class. It appears that James Gosling didn't feel that it was worth the trouble.