IDEA shows lambda compile error but compiles.
Answered
I have version 12.0.4
public static void main(String[] args) {
Optional<String> optString = Optional.of("test");
optString.ifPresent(x -> doNothing(x)); //this line shows error: Incompatible return type string in lambda expression
}
public static String doNothing(String x) {
System.out.println("hello");
return x;
}
This compiles and runs fine inside IDEA but the noted line is underlined in red and shows as an error. I can't figure out why. Any ideas?
Please sign in to leave a comment.
This IDEA version is too old. Please try the latest release: http://www.jetbrains.com/idea/download/index.html.
This bug still exists in the lastest verion of IntelliJ IDEA 2019.1.3 (Ultimate Edition).
Since no compile error occured, but this bug is very annoying. It always tell us there are errors but do not really, this make our developer blind when there is any true error.
Please report at https://youtrack.jetbrains.com/issues/IDEA with the sample project.