743 B
743 B
Mastering the IDE: Extract Function
IntelliJ IDEA allows you to extract repetitive code into a function. Select the following code in the body of the first function:
if (x <= 0) {
println("Incorrect input: $x should be positive")
return
}
Type the Extract Function
action,
or use the shortcut &shortcut:ExtractMethod;,
or click on the main menu to choose
Refactor | Extract | Function
.
Type the new function name checkArgument
and press
&shortcut:EditorEnter;.
Agree to Process Duplicates
, so that the second
occurrence of the same piece of code is also extracted.