S
S
striver2019-12-17 00:36:20
Java
striver, 2019-12-17 00:36:20

How to convert a lambda expression into a method reference?

import static java.util.stream.Collectors.joining;
import static java.util.stream.Stream.of;

public String makeSomething(String text) {
        return of(text.split(" "))
                .map(f -> myMethod(f))
                .collect(joining(" "));
    }

At the same time, there is a method: private String myMethod(String word) .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-12-17
@striver

this::myMethod
I don't remember if it's possible in Java to omit this at this point.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question