interface G {
default void print() {
System.out.println("G");
}
}
class M {
public void print() {
System.out.println("M");
}
}
class GImpl extends M implements G {}
public class Wierd {
public static void main(String[] args) {
G g=new GImpl();
g.print();
}
}
我试图在界面中使用默认方法,但是当使用 eclipse 编译时,我在第 2 行收到错误 - 说删除默认值,但我使用命令提示符编译和运行它运行正常,这可能是什么原因?
最佳答案
- 您的 eclipse 仍未使用
Java8
版本,请检查它是否小于 8。 - 使用
System.out.println(System.getProperty("java.runtime.version"));
检查。 - 您可能还需要在 Eclipse 中更改项目的构建路径和编译器级别。
还有更重要的:
关于java - 界面中的默认方法在命令提示符下运行,但在 eclipse 中不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24574293/