有没有办法从 FutureTask 中获取 Callable?

Is there a way to get a Callable back from a FutureTask?

如果我有一个 FutureTask<String> f, 我可以得到他的构造函数中使用的 Callable<String> c 对象吗?

类似于:

Callable<String> c = f.getCallable();

不适用于 FutureTask 本身,但您可以根据自己的需要对其进行扩展:

class YourFutureTask extends FutureTask<String> {

  private Callable<String> callable;

  public YourFutureTask(Callable<String> callable){
     super(callable);
     this.callable = callable;
  }

  public Callable<String> getCallable(){
     return callable;
  }
}