最初のステートメントは動作しますが、2番目のエラーは以下の理由で発生します。なぜですか?エラーを返すjavaストリームの収集関数
java.util.Arrays.asList(1,2,3,4,5).stream()
.map(n -> n+1)
.collect(Collectors.toList());
List<Integer> list = IntStream.rangeClosed(1, 10)
.map(n -> n + 1)
.collect(Collectors.toList());
ERROR:
Type mismatch: cannot convert from Collector<Object,capture#5-of ?,List<Object>>
to Supplier<R>
IntStreamは基本的なint値のストリームであり、ボックス化されたInteger値ではないためです。 – Andreas