My code looks like this:
class A {
public void m() {
Arrays.stream("a", "b")
.map(x -> x + "!") // <-- lambda expression
.forEachOrdered(System.out::println);
}
}
I want to refactor it into:
class A {
public void m() {
Arrays.stream("a", "b")
.map(this::t) // <-- method reference
.forEachOrdered(System.out::println);
}
public String t(String x) {
return x + "!";
}
}
How can I do this refactoring with IntelliJ?
Select the lambda, press Alt+Enter, click "Extract to Method Reference".
First, do the refactoring extract method on x + "!"
code. Then use quick-fix replace with method reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With