Java 8: Generic type inference improvements

Viewed 3527

With JEP 101: Generalized Target-Type Inference, this

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:

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.

3 Answers
Related