调用invokeall时如何在future.get中处理多个返回类型?
List<Future<List<Object>>> futureListe = executor.invokeAll(Classableobjekts); //Objekts list contain two objects of different types say Class1 and CLass2.
futureListe.stream()
.map(future -> {
try {
return future.get().get(0);
}
catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
}
}).forEach(d -> {
if(d instanceof Class1) { //So after response i want to check for particular response which is different for each other
do this;
}
});
} catch (InterruptedException ex) {
}
如果将来返回多种类型或者是否有更好的方法来处理这种情况,它是否是正确的处理方式?