---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 11 Edition"
java_version: 11
chapter: "Chapter 15. Expressions"
section: "15.13.2"
heading: "15.13.2. Type of a Method Reference"
parent: "15.13. Method Reference Expressions"
source: https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.13.2
id: "15.13.2"
url: https://jvm.obfuscated.software/jls/se11/15.13.2.html
raw: https://jvm.obfuscated.software/jls/se11/15.13.2.md
---

# 15.13.2. Type of a Method Reference

A method reference expression is compatible in an assignment context, invocation context, or casting context with a target type T if T is a functional interface type ([§9.8](9.8.md)) and the expression is *congruent* with the function type of the *ground target type* derived from T.

The *ground target type* is derived from T as follows:

- If T is a wildcard-parameterized functional interface type, then the ground target type is the non-wildcard parameterization ([§9.9](9.9.md)) of T.
- Otherwise, the ground target type is T.

A method reference expression is *congruent* with a function type if both of the following are true:

- The function type identifies a single compile-time declaration corresponding to the reference.

- One of the following is true:

  - The result of the function type is `void`.
  - The result of the function type is R, and the result of applying capture conversion ([§5.1.10](5.1.10.md)) to the return type of the invocation type ([§15.12.2.6](15.12.2.6.md)) of the chosen compile-time declaration is R' (where R is the target type that may be used to infer R'), and neither R nor R' is `void`, and R' is compatible with R in an assignment context.

If unchecked conversion was necessary for the compile-time declaration to be applicable, and this conversion would cause an unchecked warning in an invocation context, then a compile-time unchecked warning occurs, unless suppressed by `@SuppressWarnings` ([§9.6.4.5](9.6.4.5.md)).

If unchecked conversion was necessary for the return type R', described above, to be compatible with the function type's return type, R, and this conversion would cause an unchecked warning in an assignment context, then a compile-time unchecked warning occurs, unless suppressed by `@SuppressWarnings`.

If a method reference expression is compatible with a target type T, then the type of the expression, U, is the ground target type derived from T.

It is a compile-time error if any class or interface mentioned by either U or the function type of U is not accessible ([§6.6](6.6.md)) from the class or interface in which the method reference expression appears.

For each non-`static` member method `m` of U, if the function type of U has a subsignature of the signature of `m`, then a notional method whose method type is the function type of U is said to override `m`, and any compile-time error or unchecked warning specified in [§8.4.8.3](8.4.8.3.md) may occur.

For each checked exception type X listed in the `throws` clause of the invocation type of the compile-time declaration, X or a superclass of X must be mentioned in the `throws` clause of the function type of U, or a compile-time error occurs.

The key idea driving the compatibility definition is that a method reference is compatible if and only if the equivalent lambda expression `(x, y, z) -> exp.<T1, T2>method(x, y, z)` is compatible. (This is informal, and there are issues that make it difficult or impossible to formally define the semantics in terms of such a rewrite.)

These compatibility rules provide a convenient facility for converting from one functional interface to another:

```
Task t = () -> System.out.println("hi");
Runnable r = t::invoke;
```

The implementation may be optimized so that when a lambda-derived object is passed around and converted to various types, this does not result in many levels of adaptation logic around the core lambda body.

Unlike a lambda expression, a method reference can be congruent with a generic function type (that is, a function type that has type parameters). This is because the lambda expression would need to be able to declare type parameters, and no syntax supports this; while for a method reference, no such declaration is necessary. For example, the following program is legal:

```
interface ListFactory {
    <T> List<T> make();
}

ListFactory lf  = ArrayList::new;
List<String> ls = lf.make();
List<Number> ln = lf.make();
```
