- 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
Reference to an instance method using method references in Java8
Lambda expressions In Java allows you to pass functionality as an argument to a method. You can also call an existing method using lambda expressions.
list.forEach(n -> System.out.println(n));
Method references are simple, easy-to-read lambda expressions to call/refer and existing method by name in a lambda expression.
Syntax
Following is the syntax to reference a instance method in Java
Object:methodName
Example
Following Java example references a instance method in Java.
interface myInterface{ void greet(); } public class MethodReferences { public static void demo() { System.out.println("Sample method"); } public static void main(String args[]) { MethodReferences obj = new MethodReferences(); myInterface in = obj::demo; in.greet(); } }
Output
Sample method
- Related Articles
- Reference to a static method using method references in Java8
- Reference to a constructor using method references in Java8
- What are method references in Java8?
- How to implement an instance method of an arbitrary object using method reference in Java?
- How to implement an instance method reference using a class name in Java?
- How to implement reference to an instance method of a particular object in Java?
- Why java8 introduces default method in an interface?
- How to implement an action listener using method reference in Java?
- How to implement ActionEvent using method reference in JavaFX?
- How to create a thread using method reference in Java?
- What are the method references in Java?
- How to use method references with Generics in Java?
- How to implement ToIntFunction using lambda and method reference in Java?
- How to implement LongBinaryOperator using lambda and method reference in Java?
- How to implement LongFunction using lambda and method reference in Java?

Advertisements