method reference

A compact way to pass an existing method as a function, written Type::method, such as String::toUpperCase or User::active.

In more detail

A method reference behaves like a lambda that only calls that method. In stream pipelines it names which accessor or conversion each step uses, which often reads more clearly than a lambda.

Examples

.map(String::toUpperCase)
.flatMap(List::stream)

Related terms

Taught in

References

Certification courses