---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 5. Loading, Linking, and Initializing"
section: "5.4.3.5"
heading: "5.4.3.5. Method Type and Method Handle Resolution"
parent: "5.4.3. Resolution"
source: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5
id: "5.4.3.5"
url: https://jvm.obfuscated.software/jvms/se8/5.4.3.5.html
raw: https://jvm.obfuscated.software/jvms/se8/5.4.3.5.md
---

# 5.4.3.5. Method Type and Method Handle Resolution

To resolve an unresolved symbolic reference to a method type, it is as if resolution occurs of unresolved symbolic references to classes and interfaces ([§5.4.3.1](5.4.3.1.md)) whose names correspond to the types given in the method descriptor ([§4.3.3](4.3.3.md)).

Any exception that can be thrown as a result of failure of resolution of a class reference can thus be thrown as a result of failure of method type resolution.

The result of successful method type resolution is a `reference` to an instance of `java.lang.invoke.MethodType` which represents the method descriptor.

Method type resolution occurs regardless of whether the run time constant pool actually contains symbolic references to classes and interfaces indicated in the method descriptor. Also, the resolution is deemed to occur on *unresolved* symbolic references, so a failure to resolve one method type will not necessarily lead to a later failure to resolve another method type with the same textual method descriptor, if suitable classes and interfaces can be loaded by the later time.

Resolution of an unresolved symbolic reference to a method handle is more complicated. Each method handle resolved by the Java Virtual Machine has an equivalent instruction sequence called its *bytecode behavior*, indicated by the method handle's *kind*. The integer values and descriptions of the nine kinds of method handle are given in Table 5.4.3.5-A.

Symbolic references by an instruction sequence to fields or methods are indicated by `C.x:T`, where `x` and `T` are the name and descriptor ([§4.3.2](4.3.2.md), [§4.3.3](4.3.3.md)) of the field or method, and `C` is the class or interface in which the field or method is to be found.

**Table 5.4.3.5-A. Bytecode Behaviors for Method Handles**

| Kind | Description | Interpretation |
|---|---|---|
| 1 | `REF_getField` | `getfield C.f:T` |
| 2 | `REF_getStatic` | `getstatic C.f:T` |
| 3 | `REF_putField` | `putfield C.f:T` |
| 4 | `REF_putStatic` | `putstatic C.f:T` |
| 5 | `REF_invokeVirtual` | `invokevirtual C.m:(A*)T` |
| 6 | `REF_invokeStatic` | `invokestatic C.m:(A*)T` |
| 7 | `REF_invokeSpecial` | `invokespecial C.m:(A*)T` |
| 8 | `REF_newInvokeSpecial` | `new C; dup; invokespecial C.<init>:(A*)V` |
| 9 | `REF_invokeInterface` | `invokeinterface C.m:(A*)T` |

Let `MH` be the symbolic reference to a method handle ([§5.1](5.1.md)) being resolved. Then:

- Let R be the symbolic reference to the field or method contained within `MH`.

  (R is derived from the `CONSTANT_Fieldref`, `CONSTANT_Methodref`, or `CONSTANT_InterfaceMethodref` structure referred to by the `reference_index` item of the `CONSTANT_MethodHandle` from which `MH` is derived.)

- Let T be the type of the field referenced by R, or the return type of the method referenced by R. Let A\* be the sequence (perhaps empty) of parameter types of the method referenced by R.

  (T and A\* are derived from the `CONSTANT_NameAndType` structure referred to by the `name_and_type_index` item in the `CONSTANT_Fieldref`, `CONSTANT_Methodref`, or `CONSTANT_InterfaceMethodref` structure from which R is derived.)

To resolve `MH`, all symbolic references to classes, interfaces, fields, and methods in `MH`'s bytecode behavior are resolved, using the following three steps:

- First, R is resolved.

- Second, resolution occurs as if of unresolved symbolic references to classes and interfaces whose names correspond to each type in A\*, and to the type T, in that order.

- Third, a reference to an instance of `java.lang.invoke.MethodType` is obtained as if by resolution of an unresolved symbolic reference to a method type that contains the method descriptor specified in Table 5.4.3.5-B for the kind of `MH`.

  It is as if the symbolic reference to a method handle contains a symbolic reference to the method type that the resolved method handle will eventually have. The detailed structure of the method type is obtained by inspecting Table 5.4.3.5-B.

In each step, any exception that can be thrown as a result of failure of resolution of a class or interface or field or method reference can be thrown as a result of failure of method handle resolution.

The intent is that resolving a method handle can be done in exactly the same circumstances that the Java Virtual Machine would successfully resolve the symbolic references in the bytecode behavior. In particular, method handles to `private` and `protected` members can be created in exactly those classes for which the corresponding normal accesses are legal.

**Table 5.4.3.5-B. Method Descriptors for Method Handles**

| Kind | Description | Method descriptor |
|---|---|---|
| 1 | `REF_getField` | `(C)T` |
| 2 | `REF_getStatic` | `()T` |
| 3 | `REF_putField` | `(C,T)V` |
| 4 | `REF_putStatic` | `(T)V` |
| 5 | `REF_invokeVirtual` | `(C,A*)T` |
| 6 | `REF_invokeStatic` | `(A*)T` |
| 7 | `REF_invokeSpecial` | `(C,A*)T` |
| 8 | `REF_newInvokeSpecial` | `(A*)C` |
| 9 | `REF_invokeInterface` | `(C,A*)T` |

The result of successful method handle resolution is a `reference` to an instance of `java.lang.invoke.MethodHandle` which represents the method handle `MH`.

The type descriptor of this `java.lang.invoke.MethodHandle` instance is the `java.lang.invoke.MethodType` instance produced in the third step of method handle resolution above.

The type descriptor of a method handle is such that a valid call to `invokeExact` in `java.lang.invoke.MethodHandle` on the method handle has exactly the same stack effects as the bytecode behavior. Calling this method handle on a valid set of arguments has exactly the same effect and returns the same result (if any) as the corresponding bytecode behavior.

If the method referenced by R has the `ACC_VARARGS` flag set ([§4.6](4.6.md)), then the `java.lang.invoke.MethodHandle` instance is a variable arity method handle; otherwise, it is a fixed arity method handle.

A variable arity method handle performs argument list boxing (JLS §15.12.4.2) when invoked via `invoke`, while its behavior with respect to `invokeExact` is as if the `ACC_VARARGS` flag were not set.

Method handle resolution throws an `IncompatibleClassChangeError` if the method referenced by R has the `ACC_VARARGS` flag set and either A\* is an empty sequence or the last parameter type in A\* is not an array type. That is, creation of a variable arity method handle fails.

An implementation of the Java Virtual Machine is not required to intern method types or method handles. That is, two distinct symbolic references to method types or method handles which are structurally identical might not resolve to the same instance of `java.lang.invoke.MethodType` or `java.lang.invoke.MethodHandle` respectively.

The `java.lang.invoke.MethodHandles` class in the Java SE platform API allows creation of method handles with no bytecode behavior. Their behavior is defined by the method of `java.lang.invoke.MethodHandles` that creates them. For example, a method handle may, when invoked, first apply transformations to its argument values, then supply the transformed values to the invocation of another method handle, then apply a transformation to the value returned from that invocation, then return the transformed value as its own result.
