Language

Method reference syntax

Adapts an existing method to a target interface. A bound receiver is evaluated at reference creation.

Formal Syntax & Structure

java syntaxjava
Type::method  |  receiver::method

Working Example

Example Snippetjava
import java.util.*;import java.util.function.*;public class Main {
    public static void main(String[] args) {        Function<String, Integer> parse = Integer::parseInt;        ToIntFunction<String> length = String::length;        System.out.println(parse.apply("42"));        System.out.println(length.applyAsInt("pencil"));    }}
Java Reference