Erro no stream

3 respostas
robin_show
package br.com.robson.cap9;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Mapa {
    public static void main(String[] args) throws IOException {
        Map<Path, Long> map =
                Files.lines(Paths.get("/home/robson/IdeaProjects/Java8/src/br/com/robson/cap7"))
                .filter( p -> p.endsWith(".java"))
                .collect(Collectors.toMap(
                        Function.identity(),
                        p -> lines(p).count() )); //ta acusando erro nessa linha 

        System.out.println(map);

    }

    static Stream<String> lines(Path p) {
        try {
            return Files.lines(p);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}

Alguem sabe como resolver?

3 Respostas

lvbarbosa

Qual o erro?

robin_show
Information:Kotlin: kotlinc-jvm 1.3.61 (JRE 14+36-1461)
Information:java: Errors occurred while compiling module 'Java8'
Information:javac 11 was used to compile java sources
Information:28/03/2020 18:21 - Build completed with 1 error and 0 warnings in 40 s 876 ms
/home/robson/IdeaProjects/Java8/src/br/com/robson/cap9/Mapa.java
Error:(18, 25) java: incompatible types: inference variable K has incompatible bounds
    equality constraints: java.nio.file.Path
    lower bounds: java.lang.String,T
robin_show

estou utilizando o inteliij

Criado 27 de março de 2020
Ultima resposta 28 de mar. de 2020
Respostas 3
Participantes 2