我有一个int流,并希望该流的每个元素进行一些计算,并将它们作为Map返回,其中键是int值,值是该计算的结果.我写了以下代码:
IntStream.range(0,10).collect(Collectors.toMap(Function.identity(), i -> computeSmth(i)));
其中computeSmth(整数a).我有下一个编译器错误
method collect in interface java.util.stream.IntStream cannot be applied to given types;
required: java.util.function.Supplier,java.util.function.ObjIntConsumer,java.util.function.BiConsumer
found: java.util.stream.Collector>
reason: cannot infer type-variable(s) R
(actual and formal argument lists differ in length)
我做错了什么?