http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.6
Every CONSTANT_Class_info entry in the constant_pool table which represents a class or interface C that is not a package member must have exactly one corresponding entry in the classes array.
The classes array is member of the InnerClasses attribute.
outer_class_info_index
If
Cis not a member of a class or an interface (that is, ifCis a top-level class or interface (JLS §7.6) or a local class (JLS §14.3) or an anonymous class (JLS §15.9.5)), the value of the outer_class_info_index item must be zero.
QUESTION:
It looks for me that C could be even top level class (as the previous quotation says -
"..that is, if C is a top-level class..."
but how it is possible that the C will be top level class, if the first quotation says
"...class or interface C that is not a package member..."
"not package member" means that the class must be nested right? So it can't be top level class.
I think this is a good language-lawyering case. The first statement says that
Every CONSTANT_Class_info entry in the constant_pool table which represents a class or interface C that is not a package member must have exactly one corresponding entry in the classes array.
However, it doesn't say that a top-level class is not allowed to have an entry in the classes array.
Now why it would have an entry there, I don't know. Perhaps it is for future extensibility. But the spec allows it and it will be ignored by implementations because it's not really an inner/member class.
So the statements are not technically contradictory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With