Method References



Method reference is used to refer to a method of a functional interface. It is a compact and easy form of a lambda expression. Each time when you are using a lambda expression to just referring a method, you can replace your lambda expression with method reference.

There are following types of method references in java:

  1. Reference to a static method.
  2. Reference to an instance method.
  3. Reference to a constructor.

Reference to a static method

protected static void methodReferenceWithStaticMethod() {
	List<String> names = Arrays.asList("Laulau","Kinga","Fusi");

public static void printMe(String str) {
	System.out.println("print "+str);




Reference to an Object method

List<Integer> numbers = Arrays.asList(5, 3, 50, 24, 40, 2, 9, 18);
numbers =
		  .sorted((a, b) -> a.compareTo(b)).collect(Collectors.toList());
// equivalent
numbers =;

Reference with Constructor

class User{
		private String name;
		public User(String name) { = name;

		public String getName() {
			return name;

		public void setName(String name) { = name;
		public String toString() {
			// TODO Auto-generated method stub


List<String> names = Arrays.asList("Laulau","Kinga","Fusi");
List<User> users =;


[Laulau, Kinga, Fusi]


Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

Your email address will not be published. Required fields are marked *