Back to Blog
General

Java Method Reference Syntax

java method reference syntax: Learn the four forms of Java method reference syntax with practical examples and common pitfalls to avoid in your code.

method referenceslambda expressionsfunctional interfacesJava syntaxcode readability
Diagram illustrating four types of Java method references: static, instance on object,, instance on arbitrary object, and constructor.

Java method reference syntax uses the :: operator to create a functional interface instance from an existing method. It is a a more compact alternative to a lambda expression when the lambda body only calls a method. This article explains the four forms of method references, how they correspond to lambda expressions, and where they are best applied.

The Four Forms of Method Reference Syntax

Method references are grouped into four categories based on on the kind of method they point to. The syntax for each form is distinct, and each maps to a specific lambda shape.

FormSyntaxLambda equivalent
java method reference syntax: Practical Usage and Code Examp | RYUSLOG DEV