簡體   English   中英

Collector :: toList循環推斷

[英]Collectors::toList cyclic inference

在下面的代碼中,Intellij說“循環推斷”

List<String> rows = new ArrayList<>();
rows.add("12345");
rows.add("123");
rows.add("123456");
rows = rows.stream().filter(e -> e.length() > 4).collect(Collectors::toList);
rows.stream().forEach(System.out::println);

Collectors::toList必須存在一些我無法理解的問題。

collect期望Collector不是功能性接口,因此您不能使用lambda或方法引用來提供其實現。

您只需要使用Collectors.toList()返回Collector實例,該實例會收集列表中的元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM