我的GWT DialogBox中有一个带有计时器的调整大小处理程序,它在浏览器窗口中居中。它使用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一起开箱即用。这是我试过的:
仍然给我错误。有什么想法吗?非常感谢!
答案 0 :(得分:0)
错误在于:
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
解决了这个问题。我不明白为什么它之前没有以红色突出显示它。