IDEA shows lambda compile error but compiles.


 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) {
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?

1 comment

Please sign in to leave a comment.