Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Latest commit

 

History

History
64 lines (34 loc) · 1.77 KB

File metadata and controls

64 lines (34 loc) · 1.77 KB

📎 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