Can I replace a lambda expression with an equivalent expression using IntelliJ IDEA refactoring. Thanks.
public class StateOwner {
public void addStateListener(StateChangeListener listener) { ... }
}
..
StateOwner stateOwner = new StateOwner();
stateOwner.addStateListener(
(oldState, newState) -> System.out.println("State changed")
);
Can I have IntelliJ IDEA replace the lambda expression part with
stateOwner.addStateListener(new StateChangeListener() {
public void onStateChange(State oldState, State newState) {
System.out.println("State changed")
}
});
It depends on your hot-key setting. But if you use default, you can try lead cursor on lambda narrow or lamdba arguments, then alt + Enter, then choose "replace lambda with anonymous class"
It offers that in the same way as it offers to turn your code into a lambda. Make sure you have a fairly late version.
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