我不明白为什么这个代码不会编译的invokeAll()是不是愿意接受一个Collection <Callable<T>>
ExecutorService executor = new ScheduledThreadPoolExecutor(threads);
class DocFeeder implements Callable<Boolean> {....}
...
List<DocFeeder> list = new LinkedList<DocFeeder>();
list.add(new DocFeeder(1));
...
executor.invokeAll(list);
错误味精:
The method invokeAll(Collection<Callable<T>>) in the type ExecutorService is
not applicable for the arguments (List<DocFeeder>)
list
是的Collection
DocFeeder
,它实现Callable<Boolean>
- 发生了什么?
不,*不应*编译(在Java 5) - 正因为如此非常变异的问题。基本上泛型的变化不会按照您期望的方式工作,也不应该 - 这会很危险。 – 2008-12-16 09:45:59