Last updated : July 27, 2026

Method References In Java Tutorials

Programming

➤ Method Reference kya hota hai?

Method reference ka matlab hai lambda expression ki jagah direct kisi method ka reference dena.

Syntax:

java

ClassName::methodName
objectReference::methodName
ClassName::new

Method reference teen type ke hote hain:

  1. Static method reference

  2. Instance method reference

  3. Constructor reference

1️⃣ Static Method Reference

java

@FunctionalInterface
interface MyInterface {
    public void m1();
}

public class MethodRef {

    public static void m2() {
        System.out.println("This is m2() method");
    }

    public static void main(String[] args) {
        MyInterface mi = MethodRef::m2;
        mi.m1();
    }
}

Yaha MethodRef::m2 directly m1() ke through call ho raha hai.

Lambda version hota:

java

MyInterface mi = () -> MethodRef.m2();

Method reference short version hai.

2️⃣ Instance Method Reference

plaintextCopy

public class InstanceMethodRef {

    public void m1() {
        for (int i = 1; i <= 5; i++) {
            System.out.println(i);
        }
    }

    public static void main(String[] args) {

        InstanceMethodRef im = new InstanceMethodRef();

        Runnable r = im::m1;

        Thread t = new Thread(r);
        t.start();
    }
}

Yaha object ka method reference diya gaya hai.

3️⃣ Constructor Reference

plaintext

class Doctor {

    public Doctor() {
        System.out.println("Doctor constructor....");
    }
}

public class Test {

    public static void main(String[] args) {

        Supplier<Doctor> s = Doctor::new;

        Doctor doctor = s.get();
        System.out.println(doctor.hashCode());
    }
}

Doctor::new constructor ko reference karta hai.

Job PortalJobs