おそらく Guava API に何かが欠けています。キャストせずにFutures.allAsListでExecutorService.invokeAllを使用するにはどうすればよいですか?
私のユースケースは、Callable のリストを送信し、すべてが (並行して) 実行されるまで待ちたいということです。Callables からの結果のリストにのみ関心があります。
ListeningExecutorService executor = MoreExecutors.sameThreadExecutor(); //or any other ExecutorService
List<Future<Object>> futures =
executor.invokeAll(singletonList(new Callable<Object>() {
@Override public Object call() throws Exception {
return 42;
}
}
));
Iterable<ListenableFuture<Object>> listableFutures =
(Iterable<ListenableFuture<Object>>) (Iterable) futures;
//would like to use "futures" here
ListenableFuture<List<Object>> r = Futures.allAsList(listableFutures);
System.out.println(r.get());
ListeningExecutorService.allAsList(Collection<? extends Callable<T>> tasks)
完璧な世界では、私は電話して、Future<List<T>>
またはを取得したいと思いList<T>
ます。