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
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "NestHost" |
u4 | attribute_length | bytes after this field |
u2 | host_class_index | a 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:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 621 | 8 bytes | NestHost | |
| 621 | 00 27 | attribute_name_index | #39 |
| 623 | 00 00 00 02 | attribute_length | 2 |
| 627 | 00 25 | host_class_index | #37 |
Specification: JVMS §4.7, The NestHost Attribute (Java SE 25).