0

I have following code:

Type a;
List<Pair<Consumer<LocalDate>, LocalDate>> list = new LinkedList<>();
a.getListB().stream().forEach((TypeB b) -> { 
   list.add(new Pair<>(b::setDate, b.getDate()));
  });

And eclipse allows reduction to (no error):

Type a;
List<Pair<Consumer<LocalDate>, LocalDate>> list = new LinkedList<>();
a.getListB().stream().forEach(b -> list.add(new Pair<>(b::setDate, b.getDate())));

But openJdk build fails on

[ERROR]     reason: cannot infer type-variable(s) K,V
[ERROR]       (argument mismatch; java.lang.Object is not a functional interface)

Project compliance is set to 1.8

versions: Openjdk 1.8.0-191
Eclipse 4.10

Is it ECJ bug?

JIV
  • 813
  • 2
  • 12
  • 30
  • Eclipse 4.10 is 7 releases behind and Java 8 update 191 is also pretty old. Please do not waste time using outdated software. – howlger Nov 20 '20 at 16:06
  • Do not use ```forEach``` for building up a list. Use ```.collect(toList())``` instead. – Donat Dec 21 '20 at 21:34

0 Answers0