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

70 views Asked by At

If I have a FutureTask<String> f, can I get the Callable<String> c object that was used in his constructor?

Something like:

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

There are 1 answers

0
Eric Leibenguth On BEST ANSWER

Not with FutureTask itself, but you could extend it for your own needs:

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;
  }
}