[英]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.