【发布时间】:2021-06-12 12:30:35
【问题描述】:
在尝试构建项目时,我遇到了一个错误:
错误:java:使用 --enable-preview 的无效源版本 11(预览 语言功能仅支持 15 版)
我该如何解决这个错误?
// game template
class A_Main {
private A_World world = null;
public A_Main() {
//start the game with the space shooter asteroid game
A_Frame frame = new Asteroid_Frame();
frame.displayOnScreen();
world = new Asteroid_World();
world.setGraphicSystem(frame.getGraphicSystem());
world.setInputSystem(frame.getInputSystem());
A_GameObject.setPhysicsSystem(world.getPhysicsSystem());
A_GameObject.setWorld(world);
A_TextObject.setWorld(world);
world.init();
world.run();
}
public static void main(String[] args) {
new A_Main();
}
}
【问题讨论】:
-
这远远没有足够的信息 :-) 您的源代码与错误无关,为零。您从构建工具中收到错误,您已将源版本设置为编译器无法理解的内容。可能您使用的是不支持 Java 11 的旧编译器(旧 JDK)。您需要添加构建项目的方式。 IntelliJ、Eclipse、Maven、命令行编译还是什么?
-
请说明您是如何编译代码的。该错误表明您在 Java 15 上将
--release 11(或-source 11)与--enable-preview结合使用,而在该Java 版本上您只能将--enable-preview与--release 15一起使用。