I have encountered some java8-related code in a maven project that compiles with the javac compiler, but gives compilation-errors in Eclipse (ECJ compiler differ from javac, I suppose).
I'm importing it in Eclipse-Luna with: Import => Maven => Existsing Maven Project
As a quick fix, is there a way to make Eclipse use javac in a maven-project (thus disabling the ECJ-compiler)?
EDIT: Adding a minimal poc-example of compiler-diff.
This code compiles with javac, but the List-initialization gives error in Eclipse: "The target type of this expression must be a functional interface"
package test;
import static java.util.Arrays.asList;
import java.util.List;
public class Test01 {
private static final List<MyInterface> items = asList(() -> "123", () -> "456");
public void test01() {
System.out.println("Hello");
}
public interface MyInterface {
String value();
}
}
The error disappears if you add typecasts:
private static final List<MyInterface> items = asList((MyInterface) () -> "123", (MyInterface) () -> "456");