Signature attribute
The generic type that the descriptor erases: a field declared List<String> has the descriptor Ljava/util/List; and the signature Ljava/util/List<Ljava/lang/String;>;.
- Appears on
- class, field, method, record component
- Since
- class file 49.0 (Java 5)
- javac writes it
- for every declaration whose type involves generics
- 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: "Signature" |
u4 | attribute_length | bytes after this field |
u2 | signature_index | a Utf8 generic signature |
What it is for
The generic type that the descriptor erases: a field declared List<String> has the descriptor Ljava/util/List; and the signature Ljava/util/List<Ljava/lang/String;>;. The JVM never looks at it; reflection (getGenericType) and compilers do.
This is how a library jar keeps its generics for the code compiled against it, even though the bytecode itself is erased.
How common it is
JDK 25.0.5's java.base has 14,866 Signature attributes, in 3,343 of its 7,391 classes (10,590 on methods, 1,884 on classs, 2,312 on fields, 80 on record components).
A real one, byte by byte
From Boxing.class (compiled by javac 25), on method sum:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 1100 | 8 bytes | Signature | |
| 1100 | 00 3a | attribute_name_index | #58 |
| 1102 | 00 00 00 02 | attribute_length | 2 |
| 1106 | 00 3b | signature_index | #59 |
Specification: JVMS §4.7, The Signature Attribute (Java SE 25).