Reputation: 147
Collector<Integer, List<Integer>, List<Integer>> myCollector =
Collector.of(ArrayList<Integer>::new,
(list, element) -> {list.add(element);},
(list1, list2) -> {list1.addAll(list2);},
Function.identity();,
Characteristics.values()
);
When I run the above code I expected the types used in the static function Collector.of() will be resolved but it wasn't. It invokes the following error in eclipse
The method of(Supplier, BiConsumer, BinaryOperator, Function, Collector.Characteristics...) in the type Collector is not applicable for the arguments (ArrayList::new, ( list, element) -> {}, ( list1, list2) -> {}, Function, Collector.Characteristics[])
I need help with this.
Upvotes: 2
Views: 177
Reputation: 727
Basically two issues -
A syntax error you are having, after Function.identity()
you can't have ;
.
Third parameter is missing which is a return
value.
Upvotes: 3
Reputation: 394126
You are missing a return value in the 3rd parameter (a BinaryOperator
must have a return value):
Collector<Integer, List<Integer>, List<Integer>> myCollector =
Collector.of(ArrayList<Integer>::new,
(list, element) -> {list.add(element);},
(list1, list2) -> {list1.addAll(list2); return list1;},
// ------------- added
Function.identity(),
Characteristics.values()
);
You also had an extra ;
after Function.identity()
.
Upvotes: 2