NestHost attribute

Names this class's nest host, the top-level class it is nested in.

Appears on
class
Since
class file 55.0 (Java 11)
javac writes it
for every nested class
Needed by the JVM
yes: the JVM reads it to load, verify or run the class

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "NestHost"
u4attribute_lengthbytes after this field
u2host_class_indexa Class: the top-level class of the nest

What it is for

Names this class's nest host, the top-level class it is nested in. Classes in the same nest may access each other's private members, so since Java 11 javac no longer generates access$000 accessor methods for inner classes.

How common it is

JDK 25.0.5's java.base has 4,016 NestHost attributes, in 4,016 of its 7,391 classes (4,016 on classs).

A real one, byte by byte

From EnumSwitch$1.class (compiled by javac 25), on the class:

OffsetBytesFieldValue
6218 bytesNestHost
62100 27attribute_name_index#39
62300 00 00 02attribute_length2
62700 25host_class_index#37

Open in the viewer

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