LocalVariableTypeTable attribute
The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors..
- Appears on
- Code
- Since
- class file 49.0 (Java 5)
- javac writes it
- with -g, for locals with generic types
- 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: "LocalVariableTypeTable" |
u4 | attribute_length | bytes after this field |
u2 | local_variable_type_table_length | |
{u2,u2,u2,u2,u2}[…] | local_variable_type_table | start_pc, length, name_index, signature_index, index |
What it is for
The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors.
How common it is
JDK 25.0.5's java.base has 12,446 LocalVariableTypeTable attributes, in 2,365 of its 7,391 classes (12,446 on Code attributes).
A real one, byte by byte
From Boxing.class (compiled by javac 25), on method sum, in its Code attribute:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 1064 | 18 bytes | LocalVariableTypeTable | |
| 1064 | 00 37 | attribute_name_index | #55 |
| 1066 | 00 00 00 0c | attribute_length | 12 |
| 1070 | 00 01 | table_length | 1 |
| 1072 | 10 bytes | variable 0 | values (slot 0) |
| 1072 | 00 00 | start_pc | 0 |
| 1074 | 00 28 | length | 40 |
| 1076 | 00 33 | name_index | #51 |
| 1078 | 00 38 | signature_index | #56 |
| 1080 | 00 00 | index | 0 |
Specification: JVMS §4.7, The LocalVariableTypeTable Attribute (Java SE 25).