我有一个有条件地调用另一个的方法。例如:
public boolean contionallyDoSomething(boolean something){
boolean didSomething = false;
if(something){
theSomething();
didSomething = true;
}
return didSomething;
}
public void theSomething(){
//do something
}
我想我可以将其重写为:
public boolean contionallyDoSomething(boolean something){
boolean didSomething =something && theSomething();
return didSomething;
}
public boolean theSomething(){
//do something
return true;
}
第二种方法感觉更整洁,我个人喜欢它。但是,我有点厌倦了编写这样的代码,因为它可能会回来咬我。缺点是什么?有什么优点/缺点?
谢谢