Extract Functional Variable
IntelliJ IDEA lets you extract a functional type variable.
This refactoring creates a functional expression for Java 1.8 and later versions, and an anonymous class for older versions of Java.
Extracting a functional variable
- Select the code fragment, in this example, an argument of the
- In the main menu, select .
IntelliJ IDEA opens the Extract Functional Variable dialog.
- When the selected code depends on instance fields, like in the example, the Pass field as params check box will appear and you can pass a parameter in a place of fields. However, if for example, your selected code fragment depends on any local variable or a parameter the corresponding entries would appear in the list. When you deselect one of the parameters in the dialog, the corresponding local values will be used instead. Configure your options and click OK.
- Choose an applicable functional interface from the pop-up.
- If you want, change a name of the extracted variable if you don't want to use the name suggested in the list.
As a result, IntelliJ IDEA creates lambda that you can use further. See also the functional parameter refactoring.