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
| Type | Field | What it holds |
|---|---|---|
u1 | tag | 10 |
u2 | class_index | a Class (not an interface) |
u2 | name_and_type_index | a 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:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 10 | 5 bytes | #1 Methodref | java/lang/Object.<init>:()V |
| 10 | 0a | tag | 10 (Methodref) |
| 11 | 00 02 | class_index | #2 |
| 13 | 00 03 | name_and_type_index | #3 |
Specification: JVMS §4.4, CONSTANT_Methodref_info (Java SE 25).