【发布时间】:2017-10-15 18:00:03
【问题描述】:
我刚刚开始从事 Java 项目,并使用 IntelliJ 从 GitHub 下载了源代码——我以前从未使用过 IntelliJ,但有人告诉我它是一个比 Eclipse 更好用的 IDE(这就是我上次进行 Java 开发时使用的是大约四年前)。
当我尝试在我的计算机上本地构建源代码时,从 GitHub 提取了最新的工作版本,我在几行不同的代码行上遇到编译错误 - 错误显示:
Error:(27, 34) java: diamond operator is not supported in -source 1.5 (use -source 7 or later to enable diamond operator)
这些编译错误出现的行是这样的:
return new ArrayList<>(0);
如果我选择该行,并对错误执行Alt + Enter,它会显示一条消息,说明我可以
“将语言级别设置为 7 - Diamonds、ARM、Multi-cache 等”
但是,如果我选择此选项,则不会发生任何事情...
在pom.xml文件中,有如下xml:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
但是当我查看这个错误时,我在Diamond type are not supported at this language level 找到了答案,这表明我应该使用 maven1.7 或更高版本 - 并且该项目似乎已经在使用 1.8 版本,所以我没有'不明白为什么我得到这个编译错误......
大家有什么建议吗?
【问题讨论】:
-
你检查过 itellij idea 的项目结构选项吗?
-
我是 IntelliJ 的新手...如何/在哪里检查?
-
您是在 IntelliJ 中还是在命令行中遇到问题?尝试命令行运行 mvn clean install 看看会发生什么。
标签: java maven intellij-idea version diamond-operator