所以我用的ExecutorService,想要产生可调用,这样我可以使用的invokeAll如何得到正确的语句中使用泛型
的可调用对象有不同的返回类型执行。这让我觉得我可以以类似的方式,使用通配符
Set<Callable<?>> executedCallables = new HashSet<Callable<?>>();
executedCallables.add(serviceHelper.getOwnerDetails()); --> returns Callable<OwnerDetails>
executedCallables.add(iqmServiceHelper.getUserDetails()); --> returns Callable<UserDetails>
我添加语句的invokeAll
List<Future<? extends Object>> futures = executorService.invokeAll(executedCallables);
广告这给了我编译器错误The method invokeAll(Collection<? extends Callable<T>>) in the type ExecutorService is not applicable for the arguments (Set<Callable<?>>)
这我没有得到如何解决得到完成。
有人可以指出使用中的错误和正确的用法。
刚抬起头编译器错误是JDK 6,我不认为将是更高的版本不同的JDK
PS: - 有一个类似的StackOverflow线程以及这个Collection of Callable and Generics
感谢您的答复。上述声明构造良好我还没有得到如何纠正最终陈述列表<未来<? extends Object >> futures = executorService.invokeAll(executedCallables); – Acewin
你不会拿出一个'List>',你会得到'List >'。 这里没有办法使'T'成为通配符。 –
diesieben07
谢谢,我会建议你把这点加到你的解决方案中 – Acewin