1 回答
TA贡献1799条经验 获得超8个赞
您可以使用Supplier以获得类的“延迟”执行Result:
public static Result or(Supplier<Result> r1Supplier, Supplier<Result> r2Supplier) {
Result r1 = r1Supplier.get();
if(r1.isTrue()){
return V(); //new Result with value "True";
} else if(r1.isUndefined()) {
return U(); //new Result with value "Undefined";
} else {
// only here you need to handle r2
Result r2 = r2Supplier.get();
if(r2.isTrue()){
return V(); //new Result with value "True";
} else if(r2.isUndefined()) {
return U(); //new Result with value "Undefined";
} else {
return F();
}
}
}
它可以稍微清理一下并排序得更好,但你会掌握它的窍门
添加回答
举报