gpt4 book ai didi

Java8 代码停止编译并让我进行不必要的显式转换

转载 作者:行者123 更新时间:2023-11-30 07:17:50 24 4
gpt4 key购买 nike

我最近更新到了 Eclipse Neon,我现有的代码停止编译。编译器似乎无法进行类型推断,并让我进行不必要的显式转换。我有这个示例代码:

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();
}
}

asyncCall 方法具有以下签名:

public static <T, U> Function<T, ListenableFuture<Result<T, U>>> asyncCall(
Function<T, ListenableFuture<U>> asyncMethod);

Eclipse 建议我必须转换生成的流。这是 Eclipse 错误还是我做错了什么?

最佳答案

这是 a bug在 Eclipse Mars (4.5) 中引入(有关重现示例,请参阅 bug 496942 comment 8)。同时它已得到修复(从 Eclipse Oxygen (4.7) 的里程碑 1 开始)。可以使用 this integration build 测试修复.

关于Java8 代码停止编译并让我进行不必要的显式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38080581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com