Java 7 programming in Eclipse

I installed JDK 7 and Eclipse 3.6M6 . Then I added JRE 7 as the new JRE runtime in Eclipse and set the Java 7 compiler compliance level. I can compile the following code fragment through the command line using 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 provides the following error messages.

Invalid number of arguments for type HashMap; it cannot be parameterized using Try.java/TryJava7/src line 7 arguments. Java problem

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

Although I set the Java 7 compiler to match level, it seems like Eclipse does not yet understand the Java7 syntax. Can I play with Java 7 in Eclipse?

The following is the contents of the .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 here is the contents 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 
+50
java eclipse java-7
Apr 14 '10 at 15:18
source share
5 answers

See http://wiki.eclipse.org/JDT_Core/Java7 , http://wiki.eclipse.org/PDE/API_Tools/Java7 and Error 288548 for ongoing support for 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 been merged with HEAD and R3_7_maintenance (see the eclipse-dev archive ).

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

+18
Feb 02 '11 at 15:39
source share

As Alex noted, Eclipse uses its own compiler, which currently does not support Java 7 and, as noted in the Project Plan For Eclipse Project, the Helios version , Java 7 support is delayed and separated from version 3.6:

  • ( (new) delayed) Add Java SE 7 feature support . The next release feature for Java SE is version 7, which is likely to be available in the second half of 2010. the content of this release is still that the release is expected to contain Java language extensions, including type annotations (JSR-308), modularity support (JSR-294), and other minor change languages ​​(coin design). The Eclipse Java outfit will include initial support for compiling, editing, and running the Java 7 application for those parts that are publicly available specifications (only JSR-308 at that point). [JDT Core, JDT UI] ( 288548 )

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

+40
Apr 14 '10 at 17:00
source share

Eclipse has its own built-in Java compiler. Therefore, if there is no beta testing of eclipse or something similar that can already compile Java 7, you are out of luck.

Netbeans should work.

+6
Apr 14 '10 at 15:38
source share

I check the so-called JSR 308 branch org.eclipse.jdt.core using the following CVS repository information.

 Connection type: pserver User: anonymous Host: dev.eclipse.org Port: Default Repository path: /cvsroot/eclipse Module: org.eclipse.jdt.core Tag: JSR_308 (Branch) 

Then I followed the instructions for installing a proven JDT in eclipse. Subsequently, I looked at org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java and /org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java to come up with small examples using annotations like JSR 308.

At this point, the branch maintains and generates the corresponding new attributes in the .class files when type annotations are present. But, annotation handlers do not seem to work.

+3
May 19 '10 at 20:08
source share

Support for Java 7 (BETA) is now available in JDT. See http://thecoderlounge.blogspot.com/2011/06/java-7-support-in-eclipse-jdt-beta.html

+2
Jun 28 '11 at 19:35
source share



All Articles