I'm told to convert a lambda with a parameterized constructor to a method reference

Viewed 1700

Lets say I have a class Gizmo with a constructor that takes a String. Lets say I want to convert a List<String> to a List<Gizmo>.

I might write:

List<String> strings = new ArrayList<>();
List<Gizmo> gizmos = strings
        .stream()
        .map(str -> new Gizmo(str))
        .collect(Collectors.toList());

Now, the problem is that I'm told by IntelliJ that I can replace the lambda with a method reference. Thing is, I'm pretty sure method references can't take parameters.

4 Answers
Related