简体   繁体   English

此语言级别不支持Java- Diamond类型

[英]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>

Under File->Project Structure ( Ctrl + Alt + Shift + s ) there's a section called Project Settings , and Project File->Project StructureCtrl + Alt + Shift + s )下,有一个名为Project SettingsProject

Here you can set the project language level. 您可以在此处设置项目语言级别。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java“此语言级别不支持 lambda 表达式” - Java “lambda expressions not supported at this language level” 使用 Intellij 和 Java ME 的语言级别“1.4”不支持 Generics - Generics are not supported at language level '1.4'using Intellij & Java ME Java IntelliJ 13.1.4“此语言级别不支持Lambda表达式。” - Java IntelliJ 13.1.4 “Lambda expressions are not supported at this language level.” 尝试使用此语言级别不支持的资源 - Try With Resources Not Supported at This Language Level 此语言级别不支持文字中的下划线 - Underscores in literals are not supported at this language level Java-需要使用菱形运算符; android编译器合规性级别与支持菱形运算符的级别之间的冲突 - Java - need to use diamond operator; conflict between android compiler compliance level and level supporting diamond operator 源1.6不支持Java Combo Box Diamond运算符 - Java Combo Box Diamond Operator not supported in source 1.6 为什么我得到错误 diamond operator is not supported in -source 1.5 in Java? - Why i get error diamond operator is not supported in -source 1.5 in Java? vaadin / java-如何开发Web应用程序的多种语言版本 - vaadin/java- how to develop multiple language versions of a web app 类级别的Java-executor服务关闭字段 - Java- executor service shutdown at class level field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM