您应该能够简单地将第二种方法的实现"内联"到第一种方法中.
那是,
public static void methA() {
// snippet 1
methB();
// snippet 2
}
public static void methB() {
// snippet 3
methA();
// snippet 4
}
Run Code Online (Sandbox Code Playgroud)
变
public static void methAB() {
// snippet 1
// snippet 3
methAB();
// snippet 2
// snippet 4
}
Run Code Online (Sandbox Code Playgroud)
如果第二种方法很长,并且在第一种方法中从多个点调用,那么它可能会变得混乱.