我正在使用面向 Java 开发人员的 Eclipse IDE,Kepler Service Release 2,并将 jdk1.8.0 安装为 JRE。
我正在使用 Java All-in-one For Dummies 来学习 Java SE 8,并且在使用 Swing 编写程序时,我收到此错误:token 语法错误"-", -- 预期
使用这段代码:
button1 = new JButton("Click me!");
button1.addActionListener(e -> button1Click() );
panel1.add(button1);
exitButton = new JButton("Exit");
exitButton.addActionListener(e -> exitButtonClick() );
panel1.add(exitButton);
this.add(panel1);
button1 和 exitButton 已经声明为 JButtons,我已经导入了 javax.swing.* 和 java.awt.event.*。
我该如何解决这个问题?
最佳答案
如果您使用的是开普勒,请安装此更新:http://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
然后设置
windows > preferences > java > compiler > compiler compliance level > 1.8
关于java - token "-"上的语法错误,-- 预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24152109/