如何解决如何将方法签名从void更改为CompletionStage <Void>?
class AnotherClass {
Option<Integer> validateAndGetInt(Xyz xyz,Mno mno,String strValue) {
if (strValue != null) {
int intValue = 1;
try{
intValue = Integer.parseInt(strValue);
} catch (Exception e) {
throw new Exception("err");
}
Printer.getInstance().validateInt(xyz,mno,intValue);
return Optional.of(intValue);
}
}
} // class ends
class Printer {
void validateInt(Xyz xyz,int x) {
int m = xyz.getTeamVal(mno,x);
if(m < 0) {
throw new CustomException("invalid team value");
}
}
}
我计划将void
的{{1}}移至CompletionStage<Void>
。
validate(int x)
将作如下更改,但我不确定如何在调用方中使用。
validate
有人可以帮忙解释一下如何在 CompletionStage<Void> validateInt(Xyz xyz,int x) {
CompletableFuture<Void> f = new CompletableFuture<Void>();
int m = xyz.getTeamVal(mno,x);
if(m < 0) {
f.completeExceptionally(new CustomException("invalid team value"));
} else {
f.complete(null);
}
return f;
}
中使用它吗?
我不想使用它,
AnotherClass
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。