Search code examples
javaeclipsegwtlambda

Java 8 Eclipse Luna 4.4 GWT 2.8 Error: Lambda expressions are allowed only at source level 1.8 or above


I have a resize handler with timer in my GWT DialogBox which centers the box in the browser window. It uses a lambda function:

public class MyBox extends DialogBox {

private HandlerRegistration resizeHandler = null;
private static final int TIME_GAP = 500;
private Timer resizeTimer = new Timer() {
    @Override public void run() {
        center();
    }
};

@Override
protected void onLoad() {
    addResizeListener();
}

@Override
protected void onUnload() {
    resizeTimer.cancel();
    resizeHandler.removeHandler();
}

private void addResizeListener() {
    this.resizeHandler = Window.addResizeHandler(
            (ResizeEvent event)->{resizeTimer.schedule(TIME_GAP);});
}

}

When I compile it I get:

[ERROR] Line 117: Lambda expressions are allowed only at source level 1.8 or above
     [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

I have Eclipse Luna 4.4.2 build 20150219-0600, that is supposed to work out of box with Java 8. Here is what I tried:

  • installed Kepler patch
  • checked Preferences->Java->Compiler = 1.8 for project and Eclipse env
  • checked my Java->Build Path->Class Path -- JRE libs are 1.8.0_162
  • checked Installation Details->Configuration -- everything has jdk.1.8
  • checked Installed JREs -- Java SE 1.8.0_162
  • checked that $JAVA_HOME points to jdk1.8.0_162.jdk

Still gives me error. Any thoughts? Thanks a lot!


Solution

  • The error was here:

    private void addResizeListener() {
    this.resizeHandler = Window.addResizeHandler((ResizeEvent event)->
             {resizeTimer.schedule(TIME_GAP);});}
    

    Normally it should have highlighted it with red and not allow to compile at all. But, somehow it managed to ignore it and start compilation. The correct form of lambda function is:

    private void addResizeListener() {
            this.resizeHandler = Window.addResizeHandler(event -> 
            {resizeTimer.schedule(TIME_GAP);});}
    

    Discarding all latest changes and git pull from the last point solved the case. I did not understand why it did not highlighted it with red previously.