' cannot be used with anonymous classes"-6ren"> ' cannot be used with anonymous classes"- 这个问题在这里已经有了答案: Why can't Java 7 diamond operator be used with anonymous classes? (5 个答案) 关闭 5 年前。 我-6ren">
gpt4 book ai didi

java - 编译错误 : "' < >' cannot be used with anonymous classes"

转载 作者:太空狗 更新时间:2023-10-29 22:55:07 24 4
gpt4 key购买 nike

<分区>

我非常愿意这样写:

Lists.transform(vals,
new Function<>() {
public List<ValEntry> apply(Validator<? super T> input) {
return input.validate(value);
}
});

...比这个:

Lists.transform(vals,
new Function<Validator<? super T>, List<ValEntry>>() {
public List<ValEntry> apply(Validator<? super T> input) {
return input.validate( value );
}
});

但是 Java 编译器给我以下错误信息:

'<>' cannot be used with anonymous classes

这有根本原因吗?或者只是跳过了 JDK 7 中的功能,也许他们在 8 中做了?

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