I'm trying to use StreamSupport in order to explore stream on Java 7. I've added streamsupport-1.5.4.jar to my project and written a code like this:
import java8.util.stream.Collectors;
public class FinantialStatement {
private List<Rubric> values;
public List<Rubric> getConsolidatedRubrics() {
List<Rubric> rubrics = values.stream().sorted((Rubric r1, Rubric r2) -> r1.getOrder().compareTo(r2.getOrder())).collect(Collectors.toCollection(ArrayList::new));
return rubrics;
}
}
I'm receiving the following error:
Type mismatch: cannot convert from Collector<Object,capture#1-of
?,Collection<Object>> to Collector<? super Rubric,A,R>
I've tried to apply the hint proposed by Eclipse
Add cast to '(Collector<? super Rubric, A, R>)'
but it has not solved the problem.
Does someone have any idea? Thanks.