[英]Java- Diamond types are not supported at this language level
I have just started working on a Java project, and have downloaded the source code from GitHub, using IntelliJ- I have never used IntelliJ before, but am told that it is a much better IDE to use than Eclipse (which is what I was using when I last did any Java development- about four years ago). 我刚刚开始研究Java项目,并且已经使用IntelliJ从GitHub下载了源代码 - 我之前从未使用过IntelliJ,但是我被告知它比Eclipse更好用(我正在使用它)当我上次做任何Java开发时 - 大约四年前)。
When I try to build the source locally on my computer, having pulled the latest working version from GitHub, I get a compile error on several different lines of code- the error says: 当我尝试在我的计算机上本地构建源代码时,从GitHub中提取了最新的工作版本,我在几个不同的代码行上得到了编译错误 - 错误说:
Error:(27, 34) java: diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)
错误:(27,34)java:在-source 1.5中不支持菱形运算符(使用-source 7或更高版本来启用菱形运算符)
and the lines where these compile errors appear, are lines like: 以及出现这些编译错误的行是:
return new ArrayList<>(0);
If I select the line, and do Alt + Enter
on the error, it shows a message stating that I can 如果我选择该行,并在错误上执行
Alt + Enter
,则会显示一条消息,指出我可以
"Set language level to 7- Diamonds, ARM, Multi-cache, etc"
“将语言级别设置为7-钻石,ARM,多缓存等”
However, if I select this option, nothing happens... 但是,如果我选择此选项,则没有任何反应......
In the pom.xml
file, there is the following xml: 在
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>
But when I looked this error up, I came across the answer at: Diamond type are not supported at this language level , which indicated that I should be using maven1.7 or higher- and it appears that the project is already using version 1.8, so I don't understand why I'm getting this compile error... 但是当我看到这个错误时,我遇到了答案: 在这个语言级别不支持Diamond类型 ,这表明我应该使用maven1.7或更高版本,并且看起来该项目已经在使用版本1.8,所以我不明白为什么我得到这个编译错误...
Anyone have any suggestions? 有人有什么建议吗?
Add the following code into your pom.xml file. 将以下代码添加到pom.xml文件中。
<!-- maven-compiler-plugin -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.