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
Comment actions Permalink

This IDEA version is too old. Please try the latest release: http://www.jetbrains.com/idea/download/index.html.

0
Comment actions Permalink

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
Comment actions Permalink

Please report at https://youtrack.jetbrains.com/issues/IDEA with the sample project.

0

Please sign in to leave a comment.