Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java .class file structure - The InnerClasses attribute

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 C is not a member of a class or an interface (that is, if C is 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.

like image 769
Krab Avatar asked Feb 26 '26 22:02

Krab


1 Answers

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.

like image 64
Erwin Bolwidt Avatar answered Feb 28 '26 13:02

Erwin Bolwidt