如何将方法签名从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 (将#修改为@)