简体   繁体   English

Java 8:通用类型推断改进

[英]Java 8: Generic type inference improvements

With JEP 101: Generalized Target-Type Inference , this 使用JEP 101:广义目标类型推断 ,这

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

should be reducable to 应该可以减少

    final List<Boolean> bools = Arrays.asList(true, false, true);
    final List<Character> string = bools.stream()
            .map(x -> x ? 'X' : 'O')
            .collect(Collectors.toList());

in Java 8, but the latter does not compile: 在Java 8中,但后者不编译:

Type mismatch: cannot convert from List<Object> to List<Character>

Have I got it wrong? 我弄错了吗? Or am I ahead of my tools? 还是我领先于我的工具?

I am using JDK 8 build b120 together with eclipse-SDK-4.3.1-win32-x86_64-efx-0.9.0-SNAPSHOT.zip . 我正在使用JDK 8 build b120eclipse-SDK-4.3.1-win32-x86_64-efx-0.9.0-SNAPSHOT.zip

It just works fine under IntelliJ Idea 13 which seems ahead of Eclipse for Java8 support. 它在IntelliJ Idea 13下工作正常,它似乎领先于Java支持Java8。 So I guess you just have to wait until Eclipse will be able to compile this. 所以我猜你只需要等到Eclipse才能编译它。

现在修复了这个问题,最新的JDT快照实现了所需的提议。

The example is accepted by every Eclipse release since the release of Java 8. 自Java 8发布以来,每个Eclipse发行版都接受该示例。

(Releases greater or equal P20140317-1600). (释放大于或等于P20140317-1600)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM