首页 > 解决方案 > CompletableFuture 和 handle() 方法向后移植到 Java7

问题描述

我有一个用 Java 8 编写的代码,使用 CompletableFuture 和 handle 方法:

public interface Move
{
   CompletableFuture<Boolean> move(float i);
}

然后我们创建一个 move 的 instance mover 并调用:

mover.move(i).handle(new BiFunction<Boolean, Throwable, Object>()
{
   public Object apply(Boolean b, Throwable err)
   {
      return something; //Didn't want to overwhelm the code here; in the original one a method is called
   }
}

应该如何使其向后兼容Java7?或者我应该如何解决这个问题?

标签: javaconcurrencyfuturecompletable-future

解决方案


推荐阅读