我嘗試寫降低report
對象到一個report
對象一些流的代碼。java.util.function.BiConsumer <R,R>)是不適用(不能推斷類型變量(S)R
我有這樣的Java代碼這 取字符串(請求)GET HTTP響應 - >其傳遞到與保存在內存中舊有的反應比較
我想收集ňcompare results
插入Result
對象
,最終我想骨料。將對象合併到一個對象中。
我有此代碼
請求的類型爲string
類型的sumReport report
類型的比較2 compare result
和:
Report report = requestsList
.parallelStream()
.map(request ->
getResponse(request, e2EResultLongBL, e2EResultLongFresh)
)
.map(response -> compareToBl(response, e2EResultLongBL))
.collect(null,
(sumReport, compare2) ->
{
if (sumReport == null)
{
sumReport = new Report();
}
sumReport.add(compare2);
return sumReport;
},
(report1, report2) ->
{
Report report3 = new Report();
report3.add(report2);
return report3;
});
爲什麼d o我有這個錯誤?
Error:(174, 21) java: no suitable method found for collect(<nulltype>,(sumReport[...]rt; },(report1,r[...]t3; })
method java.util.stream.Stream.<R>collect(java.util.function.Supplier<R>,java.util.function.BiConsumer<R,? super com.waze.routing.automation.dataModel.ComparisonResult>,java.util.function.BiConsumer<R,R>) is not applicable
(cannot infer type-variable(s) R
(argument mismatch; unexpected return value))
method java.util.stream.Stream.<R,A>collect(java.util.stream.Collector<? super com.waze.routing.automation.dataModel.ComparisonResult,A,R>) is not applicable
(cannot infer type-variable(s) R,A
(actual and formal argument lists differ in length))
*如何進行機制工作*:這是由javadoc的描述,在連篇累牘。你讀過了嗎?你認爲null是否是第一個參數的有效值? http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#collect-java.util.function.Supplier-java.util.function.BiConsumer-java.util。 function.BiConsumer-。另外兩個參數是BiConsumers。一個BiConsumer(s accept方法返回什麼東西? –
'collect'是一個* mutable * reduction。你不應該在累加器或組合器中返回任何東西。 –
@PaulBoddington謝謝。我很困惑。重新編寫代碼,如果我不想要一個'report'列表,但最終會有一個彙總報告? –