I have an Iterator of Iterator, from which I want to generate a 2D array. I have the following code:
StreamSupport.stream(Spliterators.spliteratorUnknownSize(rowIterator, Spliterator.ORDERED), false)
        .map((Row row) -> {
            Iterator<Cell> cellIterator = row.cellIterator();
            return StreamSupport.stream(Spliterators.spliteratorUnknownSize(cellIterator, Spliterator.ORDERED), false)
                    .map(Utils::genericCellMapper)
                    .toArray();
        })
        .toArray(Object[][]::new);
But Eclipse editor is giving compilation error: Cannot infer type argument(s) for <R> map(Function<? super T,? extends R>).
If I change the above code as:
StreamSupport.stream(Spliterators.spliteratorUnknownSize(rowIterator, Spliterator.ORDERED), false)
        .map(new Function<Row, Object[]>() {
            @Override
            public Object[] apply(Row row) {
                Iterator<Cell> cellIterator = row.cellIterator();
                List<Object> list = StreamSupport.stream(Spliterators.spliteratorUnknownSize(cellIterator, Spliterator.ORDERED), false)
                        .map(Utils::genericCellMapper)
                        .collect(Collectors.<Object>toList());
                return list.toArray(new Object[list.size()]);
            }
        })
        .toArray(Object[][]::new);
It works. What I understand that in the first variant compiler is unable to determine the return type of the mapper. Do I need to use the second variant to achieve the requirement or it is a problem with Eclipse?
Similar question from other SO threads
 
    