Extract lambda parameter
Last modified: 06 August 2021The Extract Lambda Parameter refactoring helps you extract an expression or statement into a new parameter with a lambda expression passed as a corresponding argument. For example, this could be a comparator passed to a sorting function.
The following demo illustrates the usage of the Extract Lambda Parameter refactoring, as well as Extract Function, Extract Parameter, and Live Templates:
Extract a lambda parameter
Select a code fragment you want to extract into a lambda parameter.
Call Refactor | Extract/Introduce | Lambda Parameter from the main menu or choose Lambda Parameter from the Refactor This (Ctrl+Alt+Shift+T) popup:
In the dialog that opens, specify the name, return type, and declaration placement for the new lambda parameter:
Review the changes in the Signature Preview field and click Extract. The refactoring with be applied right away:
Thanks for your feedback!