Java 8:泛型类型推断的改进 [英] Java 8: Generic type inference improvements

查看:96
本文介绍了Java 8:泛型类型推断的改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

,但后者无法编译:


类型不匹配:无法从列表< Object>列出< Character>

我错了吗?
或者我在我的工具之前?

Have I got it wrong? Or am I ahead of my tools?

我正在使用 JDK 8 build b120 以及 eclipse-SDK -4.3.1-win32-x86_64-efx-0.9.0-SNAPSHOT.zip

推荐答案

看起来像这个问题现在已经修复,最新的JDT快照实现了所需的建议。

Seems like this issue is fixed now with the latest JDT snapshot implementing the desired proposal.

这篇关于Java 8:泛型类型推断的改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆