gpt4 book ai didi

java - 在 Eclipse 中编程 Java 7

转载 作者:IT老高 更新时间:2023-10-28 20:31:24 25 4
gpt4 key购买 nike

我安装了JDK 7Eclipse 3.6M6 .然后,我在 Eclipse 中添加了 JRE 7 作为新的 JRE 执行环境,并将编译器合规级别设置为 Java 7。我可以使用 JDK 附带的 javac 通过命令行编译以下代码7.

import java.util.HashMap;
import java.util.Map;

public class Try {

public static void main(String[] args) {
Map<Integer, String> map = new HashMap<>();
}
}

但是,Eclipse 给出了以下错误消息。

Incorrect number of arguments for type HashMap; it cannot be parameterized with arguments Try.java /TryJava7/src line 7 Java Problem

Syntax error on token "<", ? expected after this token Try.java /TryJava7/src line 7 Java Problem

尽管我已将编译器的合规级别设置为 Java 7,但 Eclipse 似乎还不理解 Java7 语法。是否可以在 Eclipse 中使用 Java 7?

以下是.classpath的内容。

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>

并且,以下是.settings/org.eclipse.jdt.core.prefs的内容。

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

最佳答案

正如 Alex 所指出的,Eclipse 使用它自己的编译器,目前不支持 Java 7,正如 Project Plan For Eclipse Project, version Helios 中所述。 ,对 Java 7 的支持被推迟并与 3.6 版本分离:

  • ((new) deferred) Add support for Java SE 7 features. The next feature release of Java SE is version 7, which will probably be available in the second half of 2010. While the contents of this release are still under discussion, that release is expected to contain extensions to the Java language, including annotations on types (JSR-308), modularity support (JSR-294), and other minor language changes (Coin project). Eclipse Java tooling will include initial support for compiling, editing, and launching applications for Java 7 for those parts which have publicly available specifications (only JSR-308 at this point). [JDT Core, JDT UI] (288548)

    NOTE: In order to align our schedule with the delayed official Java 7 appearance and due to lack of publicly available specifications (including lack of a Java 7 JSR), we have decided to move the development work to a separate branch and decouple it from the 3.6 release. In that branch we will continue to develop the Java 7 features as they become publicly accessible. We will deliver separate updates for the official builds in order to provide early access to Java 7 features.

关于java - 在 Eclipse 中编程 Java 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638622/

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