java - 在 Eclipse 中编程 Java 7

标签 java eclipse java-7

我安装了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/

相关文章:

java - 在eclipse中更改多个java文件的包声明

java - 我应该在我的项目中开始使用 java7 吗?

java - 为什么我可以更改 private final ArrayList<Book>?

java - 无法添加窗口Android对话框

eclipse - 如何通过工具栏中的快捷方式在外部网络浏览器中启动 HTML 文件

java - Android 应用程序不断崩溃 [Eclipse]

unicode - 如何在Java中以编程方式识别支持哪个Unicode版本?

java - 如果您尝试使用 Java 7 构建 GAE/Java 项目,会发生什么情况?

java - libgdx 创建的项目无法在 Android 上运行

java - 获取 Web 服务器上文件的文件修改/创建时间