CONSTANT_Methodref tag 10

A reference to a method of a class.

Tag
10
Since
class file 45.0 (Java 1.0)
Size
5 bytes
Loadable
no
Referred to by
  • invokevirtual, invokespecial, invokestatic
  • MethodHandle entries of kinds 5 to 8

Layout

TypeFieldWhat it holds
u1tag10
u2class_indexa Class (not an interface)
u2name_and_type_indexa NameAndType: name and method descriptor

What it is for

A reference to a method of a class. Constructors are methods named <init>; the static initialiser, <clinit>, is never referenced.

The descriptor is part of the reference: calling println(String) and println(int) needs two different Methodrefs that share the class and the name.

How common it is

JDK 25.0.5's java.base has 98,719 Methodref constants in 6,768 of its 7,391 classes: 9.3% of all 1,059,609 constants.

A real one, byte by byte

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

OffsetBytesFieldValue
105 bytes#1 Methodrefjava/lang/Object.<init>:()V
100atag10 (Methodref)
1100 02class_index#2
1300 03name_and_type_index#3

Open in the viewer

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