Configure Eclipse to compile with javac instead of ECJ?

I came across some java8 related code in a maven project that compiles with the javac compiler but gives compilation errors in Eclipse (ECJ compiler is different from javac I suppose).

I import it into Eclipse-Luna with: Import => Maven => Existinging Maven Project

How can I quickly fix if there is a way to get Eclipse to use javac in a maven project (thus disabling the ECJ compiler)?

EDIT : Adding a minimal poc compiler-diff example.

This code compiles with javac , but initializing List gives an 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 goes away if you add typecasts:

private static final List<MyInterface> items = asList((MyInterface) () -> "123", (MyInterface) () -> "456");

      

+3


source to share





All Articles