InnerClasses attribute

Nested classes did not exist in Java 1.0, and the JVM still knows nothing about them: Outer$Inner is an ordinary top-level class to the JVM.

Appears on
class
Since
class file 45.0 (Java 1.1)
javac writes it
for every class that is or refers to a nested class
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "InnerClasses"
u4attribute_lengthbytes after this field
u2number_of_classes
{u2,u2,u2,u2}[…]classesinner_class_info_index, outer_class_info_index, inner_name_index, inner_class_access_flags

What it is for

Nested classes did not exist in Java 1.0, and the JVM still knows nothing about them: Outer$Inner is an ordinary top-level class to the JVM. This attribute records the source-level relationship for compilers and reflection: the outer class, the simple name, and the flags as declared (private, static and protected, which a top-level class cannot have).

Every class that mentions a nested class lists it, not only the outer class, so the compiler can tell Outer$Inner from a class whose name merely contains a dollar sign.

How common it is

JDK 25.0.5's java.base has 5,544 InnerClasses attributes, in 5,544 of its 7,391 classes (5,544 on classs).

A real one, byte by byte

From Hello.class (compiled by javac 25), on the class:

OffsetBytesFieldValue
106116 bytesInnerClasses
106100 34attribute_name_index#52
106300 00 00 0aattribute_length10
106700 01number_of_classes1
10698 bytesclass 0java/lang/invoke/MethodHandles$Lookup
106900 35inner_class_info_index#53
107100 37outer_class_info_index#55
107300 39inner_name_index#57
107500 19inner_class_access_flags0x0019 public static final

Open in the viewer

Specification: JVMS §4.7, The InnerClasses Attribute (Java SE 25).