Issue
This code works on Netbeans but gives an error on IntelliJ:
public static List<String> readFile(String file) throws IOException {
Path path = Paths.get("src", file);
Stream<String> lines = Files.lines(path);
return lines.collect(Collectors.toList());
}
The error is on the return
statement and says that a List<String>
is expected but the collect()
method gives a List<Object>
.
It looks like that Netbeans is able to understand that a Stream<String>
must be collected to a List<String>
while IntelliJ isn't.
What's the problem here?
EDIT: As suggested, I upgraded IntelliJ to the latest version (14.1.1) and I tried to compile my code with javac by terminal: it works. The problem must be in my IntelliJ configuration but it looks correct to me
Solution
I solved the mistery: in File Menu->Project Structure
, change Project Language Level
to 8.0 - Lambdas, type annotations etc.
Answered By - Oneiros