gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 21:39:27 25 4
gpt4 key购买 nike

我刚刚开始从事一个 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 higher to enable diamond operator)

出现这些编译错误的行如下:

return new ArrayList<>(0);

如果我选择该行,并对错误执行Alt + Enter,它会显示一条消息,说明我可以

"Set language level to 7- Diamonds, ARM, Multi-cache, etc"

但是,如果我选择这个选项,什么也不会发生...

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 版,所以我不明白为什么会出现此编译错误...

有人有什么建议吗?

最佳答案

将以下代码添加到您的 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>

关于此语言级别不支持 Java- Diamond 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44005097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com