javaeclipsejava-7

Programming Java 7 in Eclipse


I installed JDK 7 and Eclipse 3.6M6. Then, I added JRE 7 as a new JRE execution environment in Eclipse, and set the compiler compliance level to Java 7. I can compile the following piece of code through command line using the javac that comes with JDK 7.

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

public class Try {

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

But, Eclipse gives the following error messages.

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

Even though I've set the compliance level of the compiler to Java 7, it looks like Eclipse doesn't understand Java7 syntax yet. Is it possible to play with Java 7 in Eclipse?

The following is the content of .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>

And, the following is the content of .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

Solution

  • See http://wiki.eclipse.org/JDT_Core/Java7, http://wiki.eclipse.org/PDE/API_Tools/Java7 and Bug 288548 for the ongoing support of Eclipse for Java 7. And see http://wiki.eclipse.org/JDT/Eclipse_Java_7_Support_%28BETA%29 for instructions on how to evaluate Java 7 in Eclipse.

    UPDATE 1: The BETA_JAVA7 branch has been merged to HEAD and R3_7_maintenance (See the eclipse-dev archive).

    UPDATE 2: Eclipse 3.7.1 (Indigo SR1) supports Java 7.