Introduction
Java 8 introduced a variety of features that significantly eased the way developers write code, making it more readable & efficient. Method references, a part of this update, are a notable addition, allowing methods to be used as lambdas.

This article is designed to guide you through the concept of method references, their types, & practical applications in Java 8. By the end of this article, you'll have a firm understanding of this feature & how to implement it in your coding projects.
Let's begin our exploration into the world of Java 8's method references.
Types of Method References
Method references in Java 8 are a shorthand notation of a lambda expression to call a method. We'll explore the three main types of method references, providing examples & explanations for each.
Reference to a Static Method
Static method references are used when a lambda expression calls a static method. Here’s the syntax:
ClassName::staticMethodName
Let's consider an example. Suppose we have a utility class with a static method to check if a number is prime:
public class Util {
public static boolean isPrime(int number) {
// method logic
}
}
List<Integer> numbers = Arrays.asList(2, 3, 4, 5, 7, 11, 13);
numbers.stream().filter(Util::isPrime).forEach(System.out::println);
In this example, Util::isPrime is a method reference that points to the static method isPrime in Util class. It’s an alternative to the lambda expression (number) -> Util.isPrime(number).
Reference to an Instance Method of a Particular Object
Instance method references are about methods of a particular object. The syntax looks like:
instance::instanceMethodName
For instance, let's say we have a String list and we want to convert each element to uppercase:
List<String> words = Arrays.asList("Java", "Stream", "Method", "Reference");
words.stream().map(String::toUpperCase).forEach(System.out::println);
Here, String::toUpperCase refers to the toUpperCase method of the String class. This method reference is equivalent to the lambda expression (word) -> word.toUpperCase().
Reference to a Constructor
Constructor references are used to reference a constructor of a class. The syntax for this is:
ClassName::new
Consider we have a class Person:
public class Person {
String name;
Person(String name) {
this.name = name;
}
}
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
List<Person> people = names.stream().map(Person::new).collect(Collectors.toList());
In this code snippet, Person::new is a constructor reference which creates a new instance of Person for each element in the names list.