IDEA使用快捷键提炼函数(Extract Method)
1、快捷键 ------ctrl+alt+M
2、右击操作--------选中待提炼代码 --> 右击 --> Refactor --> Extract --> Method.
3、举例
提炼前:
java
public void printOwing(double amount) {
printBanner();
System.out.println("name:" + name);
System.out.println("amount:" + amount);
}
提炼后:
java
public void printOwing(double amount) {
printBanner();
printDetails(amount);
}
/**
* 描述:打印详情
*/
public void printDetails(double amount) {
System.out.println("name:" + name);
System.out.println("amount:" + amount);
}