CONSTANT_Fieldref tag 9

A reference to a field.

Tag
9
Since
class file 45.0 (Java 1.0)
Size
5 bytes
Loadable
no
Referred to by
  • getfield, putfield, getstatic, putstatic
  • MethodHandle entries of kinds 1 to 4

Layout

TypeFieldWhat it holds
u1tag9
u2class_indexa Class: the class to look the field up in
u2name_and_type_indexa NameAndType: the field's name and type descriptor

What it is for

A reference to a field. The class is where resolution starts, which is the type of the expression in the source, not necessarily the class that declares the field: the JVM searches superclasses and superinterfaces from there.

How common it is

JDK 25.0.5's java.base has 35,942 Fieldref constants in 5,402 of its 7,391 classes: 3.4% of all 1,059,609 constants.

A real one, byte by byte

Constant #9 of Hello.class, compiled by javac 25:

OffsetBytesFieldValue
685 bytes#9 Fieldrefjava/lang/System.out:Ljava/io/PrintStream;
6809tag9 (Fieldref)
6900 0aclass_index#10
7100 0bname_and_type_index#11

Open in the viewer

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