- 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 a static 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 the existing method by name in a lambda expression. You can refer to a static method defined in the class using method references.
Syntax
Following is the syntax to reference a static method in Java
ClassName:methodName
Example
The following Java example references a static 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[]) { myInterface in = MethodReferences::demo; in.greet(); } }
Output
Sample method
- Related Articles
- Reference to a constructor using method references in Java8
- Reference to an instance method using method references in Java8
- What are method references in Java8?
- How to implement ActionEvent using method reference in JavaFX?
- How to create a thread using method reference in Java?\n
- Using a JavaScript object inside a static() method?
- Why java8 introduces default method in an interface?
- How to implement an instance method of an arbitrary object using method reference in Java?
- How to call a non-static method of an abstract class from a static method in java?
- What are the method references in Java?
- How to use method references with Generics in Java?
- How to find a maximum value in a collection using method reference in Java?
- Class method vs static method in Python
- How to implement LongPredicate using lambda and method reference in Java?
- How to implement LongSupplier using lambda and method reference in Java?

Advertisements