1 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以使用Supplier以獲得類的“延遲”執(zhí)行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();
}
}
}
它可以稍微清理一下并排序得更好,但你會(huì)掌握它的竅門
添加回答
舉報(bào)