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

TypeFieldWhat it holds
u1tag12
u2name_indexa Utf8: the member's simple name
u2descriptor_indexa 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:

OffsetBytesFieldValue
185 bytes#3 NameAndType<init>:()V
180ctag12 (NameAndType)
1900 05name_index#5
2100 06descriptor_index#6

Open in the viewer

Specification: JVMS §4.4, CONSTANT_NameAndType_info (Java SE 25).