CONSTANT_NameAndType tag 12
A member's name and type without its class.
- Tag
12- Since
- class file 45.0 (Java 1.0)
- Size
- 5 bytes
- Loadable
- no
- Referred to by
- Fieldref, Methodref and InterfaceMethodref
- Dynamic and InvokeDynamic
Layout
| Type | Field | What it holds |
|---|---|---|
u1 | tag | 12 |
u2 | name_index | a Utf8: the member's simple name |
u2 | descriptor_index | a Utf8: a field or method descriptor |
What it is for
A member's name and type without its class. Splitting it out lets every reference to, say, toString:()Ljava/lang/String; share one entry, whatever the class.
How common it is
JDK 25.0.5's java.base has 139,071 NameAndType constants in 6,830 of its 7,391 classes: 13.1% of all 1,059,609 constants.
A real one, byte by byte
Constant #3 of Hello.class, compiled by javac 25:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 18 | 5 bytes | #3 NameAndType | <init>:()V |
| 18 | 0c | tag | 12 (NameAndType) |
| 19 | 00 05 | name_index | #5 |
| 21 | 00 06 | descriptor_index | #6 |
Specification: JVMS §4.4, CONSTANT_NameAndType_info (Java SE 25).