简体   繁体   中英

Collectors::toList cyclic inference

In the following code Intellij says "Cyclic inference"

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);

There must be some problems with Collectors::toList which I can't uderstand.

collect expects Collector which is not functional interface so you can't use lambda or method reference to provide its implementation.

You simply need to use Collectors.toList() which returns Collector instance which collects your elements in list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM