【发布时间】:2013-12-14 15:06:19
【问题描述】:
JEP 101: Generalized Target-Type Inference,这个
final List<Boolean> bools = Arrays.asList(true,false, true);
final List<Character> string = bools.stream()
.<Character>map(x -> x ? 'X' : 'O')
.collect(Collectors.<Character>toList());
应该可以归约为
final List<Boolean> bools = Arrays.asList(true, false, true);
final List<Character> string = bools.stream()
.map(x -> x ? 'X' : 'O')
.collect(Collectors.toList());
在 Java 8 中,但后者无法编译:
Type mismatch: cannot convert from List<Object> to List<Character>
我记错了吗? 还是我领先于我的工具?
我正在使用JDK 8 build b120 和eclipse-SDK-4.3.1-win32-x86_64-efx-0.9.0-SNAPSHOT.zip。
【问题讨论】:
-
谢谢,很有用!
-
请记住,Eclipse 不使用 JDK 编译器,因此它们的快照构建可能仍会赶上最终规范。
-
尝试用javac编译
-
这个好像还在schedule of the JDT team上。
标签: java generics type-inference java-8