Skip to content

The method reference is nothing but the simplified version of the lambda expression. Instead of providing an implementation body, a method reference refers to an existing available method

Notifications You must be signed in to change notification settings

Shubh2-0/Method-References

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Ž Method References

GitHub stars GitHub forks

Simplified Lambda Expressions

Cleaner syntax for functional programming


🎯 About

Method References are shorthand for lambda expressions that call a single method. They make code more readable and concise.

πŸ“š Types of Method References

Type Syntax Example
Static Method Class::staticMethod Math::max
Instance Method object::method str::length
Arbitrary Object Class::instanceMethod String::toUpperCase
Constructor Class::new ArrayList::new

πŸ’» Examples

// Lambda vs Method Reference
list.forEach(s -> System.out.println(s));  // Lambda
list.forEach(System.out::println);         // Method Reference

// More examples
list.stream().map(String::toUpperCase);    // Instance method
list.stream().sorted(Integer::compare);    // Static method
list.stream().collect(ArrayList::new);     // Constructor

πŸ› οΈ Technologies

Java 8+ | Lambda | Stream API

πŸ“¬ Contact

LinkedIn Gmail


Keywords: Java Method-Reference Lambda Functional-Programming Stream-API Java8

About

The method reference is nothing but the simplified version of the lambda expression. Instead of providing an implementation body, a method reference refers to an existing available method

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages