java - 无法解决 IntelliJ 上关于项目语言级别的源错误

标签 java intellij-idea javac

我尝试在 Mac 上的 IntelliJ 上构建我的项目时遇到了这样的错误。

Error:(12, 39) java: diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

Error:(122, 48) java: method references are not supported in -source 1.5
  (use -source 8 or higher to enable method references)

Error:(124, 51) java: lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

查看本站其他答案,与项目语言水平太低有关。但是,我的设置如下:

Screenshot of Project Settings

似乎我选择了正确的选项,但我仍然遇到同样的错误。我该如何解决这些问题。

如果我使用 JDK 11.0.1,这是日志的第一部分:

Information:java: JPS build failed to load optimized file manager for javac:
java.lang.NoClassDefFoundError: com/sun/tools/javac/util/DefaultFileManager
java.lang.NoClassDefFoundError: com/sun/tools/javac/file/JavacFileManager
Information:java: Errors occurred while compiling module 'notification-processor'
Information:javac 8 was used to compile java sources
Information:Module "notification-processor" was fully rebuilt due to project configuration/dependencies changes
Information:2018-11-07, 4:38 PM - Compilation completed with 19 errors and 4 warnings in 3 s 490 ms
Warning:java: class org.jetbrains.jps.javac.ast.ExternalRefCollectorCompilerToolExtension : com/sun/source/util/TaskListener
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.

如果我使用 JDK 8,这是日志的第一部分:

Information:java: Errors occurred while compiling module 'notification-processor'
Information:javac 1.8.0_191 was used to compile java sources
Information:Module "notification-processor" was fully rebuilt due to project configuration/dependencies changes
Information:2018-11-07, 4:39 PM - Compilation completed with 19 errors and 3 warnings in 2 s 858 ms
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.

最佳答案

请确保您没有覆盖模块设置中的语言级别:

enter image description here

和编译器设置

enter image description here

关于java - 无法解决 IntelliJ 上关于项目语言级别的源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53198264/

相关文章:

java - Android 中可中断的 ScheduledExecutorService

java - 为什么不直接使用实例字段,而是赋值给一个局部变量呢?

java - Intellij doExecute 不使用 DefaultProgramRunner 触发

警告对话框中的 Java FX 自定义图片

java - 编译 module-info.java 抛出错误 : module not found

java - 添加 RedirectAttributes 参数导致 Spring MVC Controller 方法中出现 "Model has no value for key"异常

java - Ubuntu下构建libvirt-java

java - 线程 "main"java.lang.NoClassDefFoundError : org/jvnet/staxex/XMLStreamReaderEx 中出现异常

optimization - 在 javac 中禁用优化?

java - 如何使用另一个程序编译Java程序?