Joh*_*hnD 1 java java-8 java-stream
在下面的代码中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);
Run Code Online (Sandbox Code Playgroud)
必须有一些Collectors::toList我无法理解的问题.
collect期望Collector哪个不是功能接口,因此您不能使用lambda或方法引用来提供其实现.
您只需要使用Collectors.toList()哪个返回收集列表中元素的Collector实例.