I have recently updated to the Eclipse Neon and my existing code stop to compile. It seem to be that the compiler can not do the type inference, and make me to do an unnecessary explicit casting. I have this example code:
public class ProductManager {
//Mocked: originaly a Bean
com.google.common.util.concurrent.ListeningExecutorService executor;
public Stream<Result<Product, ItineraryDTO>> getItineraries(Set<Product> productsSet) {
// Asynchronously get itinerary for every flight
Stream<ListenableFuture<Result<Product, ItineraryDTO>>> futures =
productsSet.stream().map(Result.asyncCall(product ->
this.executor.submit(() -> this.getItinerary(product)
)));
// Wait and get results for every submitted task
Stream<Result<Product, ItineraryDTO>> results = Result.waitAndGet(futures);
return results;
}
private ItineraryDTO getItinerary(Product flight) {
// Mocked: originaly get itinerary from a REST service
return new ItineraryDTO();
}
}
The asyncCall
method has this signature:
public static <T, U> Function<T, ListenableFuture<Result<T, U>>> asyncCall(
Function<T, ListenableFuture<U>> asyncMethod);
Eclipse suggest that i have to cast the resulting stream. Is this an Eclipse bug or am i doing something wrong?
This was a bug introduced in Eclipse Mars (4.5) (see bug 496942 comment 8 for a reproducing example). It has meanwhile been fixed (as of milestone 1 towards Eclipse Oxygen (4.7)). The fix can be tested using this integration build.