问题描述
以下代码块在1.8.11中编译得很好,但在1.8.20中抛出错误
The following block of code compiles just fine in 1.8.11, but throws an error in 1.8.20
private static String calculateSyntheticOrderTypePrice(
FluentIterable<? extends CalculatorProvider> pendingProviders )
{
FluentIterable <? extends CalculatorProvider> mlsLegProvidersAll = pendingProviders.filter(Predicates.and(
IS_MLS_PROVIDER, Predicates.not(IS_SYNTHETIC)));
FluentIterable <? extends CalculatorProvider> mlsLegProvidersNewest = reduceToNewestMlsPrices(mlsLegProvidersAll);
FluentIterable <? extends CalculatorProvider> otherLegProviderAll = pendingProviders.filter(Predicates.and(
Predicates.not(IS_MLS_PROVIDER), Predicates.not(IS_SYNTHETIC)));
FluentIterable <String> mlsHeadPriceTypes = mlsLegProvidersNewest.transform(TO_MLS_SPREAD_PRICE_FUN); /* MLS head: spread price */
FluentIterable <String> orderPriceTypes = otherLegProviderAll.transform(TO_ORDER_TYPE_PRICE_FUN); /* non-MLS orders: option spread or pairs */
FluentIterable <String> formattedOrderHeadPriceTypes = orderPriceTypes.transform(new FormatOrderTypePriceFun(creditOrDebit(otherLegProviderAll)));
FluentIterable <String> allFormatted = FluentIterable.from(Iterables.concat(mlsHeadPriceTypes, formattedOrderHeadPriceTypes));
return CalculatorValues.rollupStrings(allFormatted);
}
我得到的错误是java:找不到适合filter的方法(com。 google.common.base.Predicate)
The error I get is java:not suitable method found for filter (com.google.common.base.Predicate)
更新8和20之间是否有更改会影响此代码?我在两种情况下使用相同版本的guava 17.0(最新稳定版),唯一的变化是Java中的更新版本。
Was there a change between update 8 and 20 that would affect this code? I am using the same version of guava in both cases 17.0 (latest stable) and the only change is update version in Java.
非常感谢任何帮助。
编辑
显示错误的行是
FluentIterable <? extends CalculatorProvider> mlsLegProvidersAll = pendingProviders.filter(Predicates.and(
IS_MLS_PROVIDER, Predicates.not(IS_SYNTHETIC)));
推荐答案
这很可能是是在JDK 8u11之后推出的,在JDK 8u20中找到但是来不及修复,并在之后修复JDK 8u20。修复程序显示在快照构建版本b02和快照构建b27。
This is most likely JDK-8051402 which was introduced after JDK 8u11, found in JDK 8u20 but too late to fix, and was fixed after JDK 8u20. The fix appears in the JDK 8u40 early access snapshot build b02 and in the JDK 9 early access snapshot build b27.
这是一个最小化的代码片段这说明了问题:
Here's a minimized code fragment that illustrates the problem:
public class X {
static Predicate<Number> IS_SYNTHETIC = p -> false;
static Predicate<Number> IS_MLS_PROVIDER = p -> true;
static void calcSynth(Stream<? extends Number> providers) {
Stream<? extends Number> all =
providers.filter(Predicates.and(IS_MLS_PROVIDER,
Predicates.not(IS_SYNTHETIC)));
}
}
class Predicates {
static <T> Predicate<T> and(Predicate<? super T> p1, Predicate<? super T> p2) {
return x -> p1.test(x) && p2.test(x);
}
static <T> Predicate<T> not(Predicate<T> p) {
return x -> !p.test(x);
}
}
这适用于JDK 8u11的javac,在JDK 8u20上失败,再次使用JDK 8u40-b02和JDK9-b27。
This works on JDK 8u11's javac, fails on JDK 8u20, and works again on JDK 8u40-b02 and JDK9-b27.
这篇关于Java 1.8.20编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!