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?

3 comments

This bug still exists in the lastest verion of IntelliJ IDEA 2019.1.3 (Ultimate Edition).

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.RowFactory;

public class Test {
public static void main(String[] args) {
JavaRDD<String> rdd = null;
JavaRDD<Row> otherRDD = rdd.map(rid -> RowFactory.create(rid));
}
}


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.


0

Please sign in to leave a comment.