JavaIntermediate#java8#lambda

What is a method reference and what are its types?

A method reference is shorthand for a lambda that calls an existing method, using :: syntax. Types include static (Class::staticMethod), instance on a particular object (obj::method), instance on an arbitrary object (Class::instanceMethod), and constructor references (Class::new).

Example
List<String> names = List.of("bob","amy");
names.forEach(System.out::println); // instance method reference on particular object
names.stream().map(String::toUpperCase); // instance method on arbitrary object

Related Questions

1
JavaIntermediate#streams

What is the difference between Stream.reduce() with and without an identity value?

Open
2
JavaAdvanced#streams

What is a parallel stream and when should you avoid it?

Open
3
JavaAdvanced#memory#gc

What are the different generations in the JVM heap?

Open