- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the method references in Java?
Method reference is the way in a lambda expression to refer a method without executing it. In the body of a lambda expression, we can able to call another method if they are compatible with a functional interface.
The operator "::" can be used to separate the class name from the method name.
Method reference to a static method
A static method has referred by using the class name. In lambda expression, we can refer to a static method by using the below syntax.
Syntax
Class-name :: Method-name;
Example
interface Test { void func(); } class StaticMethodRef { static void message() { System.out.println("Welcome to Tutorials Point"); } } public class LambdaMethodRefTest1 { public static void main(String arg[]) { Test test = StaticMethodRef :: message; // calling using "::" operator test.func(); } }
Output
Welcome to Tutorials Point
Method reference to an instance method
An instance method has referred by using a lambda expression. We need to refer an instance method, use an instance name instead of a class name. The "::" operator can be used to refer to instance methods also.
Syntax
Instance-name :: Method-name;
Example
interface Test { void func(); } class InstanceMethodRef { void message() { System.out.println("Welcome to Tutorix"); } } public class LambdaMethodRefTest2 { public static void main(String arg[]) { InstanceMethodRef ref = new InstanceMethodRef(); Test test = ref :: message; // calling using "::" operator test.func(); } }
Output
Welcome to Tutorix
- Related Articles
- What are method references in Java8?
- What are the constructor references in Java?
- How to use method references with Generics in Java?
- What are circular references in C#?
- How to use IntStream in lambdas and method references in Java?
- Types of References in Java
- What is the difference between Java references and pointers in other languages?
- Reference to a static method using method references in Java8
- Reference to an instance method using method references in Java8
- Back references in Java regular expressions
- Reference to a constructor using method references in Java8
- What are the rules on method overriding in Java?
- What are the differences between paint() method and repaint() method in Java?
- What are the differences between printStackTrace() method and getMessage() method in Java?
- C/C++ Pointers vs Java references

Advertisements