簡體   English   中英

Java 8 Eclipse Luna 4.4 GWT 2.8錯誤:Lambda表達式僅在源級別1.8或更高級別上才允許

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

我在GWT對話框中有一個帶有計時器的調整大小處理程序,該對話框將框置於瀏覽器窗口的中心。 它使用lambda函數:

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);});
}

}

當我編譯它時,我得到:

[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

我有Eclipse Luna 4.4.2 build 20150219-0600,應該與Java 8兼容使用。這是我嘗試的:

  • 安裝的開普勒補丁
  • 為項目和Eclipse env檢查了Preferences-> Java-> Compiler = 1.8
  • 檢查了我的Java-> Build Path-> Class Path-JRE庫是1.8.0_162
  • 檢查安裝詳細信息->配置-一切都有jdk.1.8
  • 已檢查已安裝的JRE-Java SE 1.8.0_162
  • 檢查$ JAVA_HOME指向jdk1.8.0_162.jdk

仍然給我錯誤。 有什么想法嗎? 非常感謝!

錯誤在這里:

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

通常,它應該用紅色突出顯示它,並且根本不允許編譯。 但是,它設法以某種方式忽略了它並開始編譯。 lambda函數的正確形式為:

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

放棄所有最新更改並從最后一點開始進行git pull解決了該情況。 我不明白為什么以前沒有用紅色突出顯示它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM