Record attribute
The components of a record, in order, each with its own attributes (Signature, annotations).
- Appears on
- class
- Since
- class file 60.0 (Java 16)
- javac writes it
- for record classes
- Needed by the JVM
- no: it is for the class libraries (reflection), compilers or tools
Layout
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "Record" |
u4 | attribute_length | bytes after this field |
u2 | components_count | |
record_component_info[…] | components | name_index, descriptor_index, attributes_count, attributes |
What it is for
The components of a record, in order, each with its own attributes (Signature, annotations). Class.getRecordComponents() reads it; serialization uses it to construct records through their canonical constructor.
The JVM itself treats a record as an ordinary final class that extends java.lang.Record.
How common it is
JDK 25.0.5's java.base has 190 Record attributes, in 190 of its 7,391 classes (190 on classs).
A real one, byte by byte
From Point.class (compiled by javac 25), on the class:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 1580 | 20 bytes | Record | |
| 1580 | 00 3a | attribute_name_index | #58 |
| 1582 | 00 00 00 0e | attribute_length | 14 |
| 1586 | 00 02 | components_count | 2 |
| 1588 | 6 bytes | component 0 | x |
| 1588 | 00 12 | name_index | #18 |
| 1590 | 00 13 | descriptor_index | #19 |
| 1592 | 2 bytes | attributes | 0 |
| 1592 | 00 00 | attributes_count | 0 |
| 1594 | 6 bytes | component 1 | y |
| 1594 | 00 16 | name_index | #22 |
| 1596 | 00 13 | descriptor_index | #19 |
| 1598 | 2 bytes | attributes | 0 |
| 1598 | 00 00 | attributes_count | 0 |
Specification: JVMS §4.7, The Record Attribute (Java SE 25).