我想在 method-2 中调用 method-1 但在 method-1 中进行一些修改?
I want to call a method-1 in method-2 but with some amendments in method-1?
public void method_1()
{
code statement 1
code statement 2
}
我想在不执行代码语句 1 的情况下调用方法 1,如下所示:
public void method_2()
{
call method_1 without code statement 1
}
我该怎么做?
您可以在method_1中添加一个参数,您可以根据该参数决定是否执行语句1。类似这样:
public void method_1(boolean withStatement1){
if (withStatement1){
code statement 1
}
code statement 2
}
public void method_2(){
call method_1(false);
}
public void method_1()
{
code statement 1
code statement 2
}
我想在不执行代码语句 1 的情况下调用方法 1,如下所示:
public void method_2()
{
call method_1 without code statement 1
}
我该怎么做?
您可以在method_1中添加一个参数,您可以根据该参数决定是否执行语句1。类似这样:
public void method_1(boolean withStatement1){
if (withStatement1){
code statement 1
}
code statement 2
}
public void method_2(){
call method_1(false);
}