openjdk 1.7 in eclipse: operator is not allowed for source level below 1.7

JavaEclipseWindows RuntimeOpenjdk

Java Problem Overview


Eclipse gives me an error:

'<>' operator is not allowed for source level below 1.7	

I guess this is because it is not using java 1.7. Except that it is. At least openjdk 1.7 (my OS is OpenSuse 12.3).

I switched back from kepler to juno to reduce some lags and try to figure out this bug as well, to no avail so far.

Some things I have tried:

  • the default runtime for eclipse is opensdk 1.7 (says so in help, about, installation details)
  • project properties, java build -> library. I have manually added the opensdk location.

I would install the oracle version, but there is only 1.6 available from the opensuse repository. I already tried installing the rpm offered by oracle, that didn't put itself in my path and kind of messed everything up, so I removed that again.

It should work with openjdk as well no? Or do you think it has a bug?

ps: junit also was not recognised, so I manually linked to the jar file. Perhaps this is relevant information.

Java Solutions


Solution 1 - Java

In your project's preferences, you must set the compiler --source option to 1.7 and --target option to 1.7 also. There are dedicated option boxes for that.

Right-click on the project. Choose Properties. Choose Java Compiler on the left. Choose 1.7 for the Compiler Compliance level. If the 2 drop-downs below that aren't 1.7, uncheck Use default compliance settings and set those to 1.7.

Solution 2 - Java

right click on the error, choose quick fix, and select change JRE to 1.7

Solution 3 - Java

If you want to use below version, use

Map<String, Integer> map = new HashMap<String, Integer>();

instead of

HashMap<String, Integer> map = new HashMap<>();

Solution 4 - Java

right click on Project - properties - Java Complier - Compiler compliance -set level 1.7

Solution 5 - Java

If you would like to stick with java 1.6, Search and replace <> with empty string. You'll get compiler warnings but the errors should go away.

Solution 6 - Java

I had the same problem, but with the

  • Compiler Compliance Level
  • Generated .class files compatibility
  • Source compatibility all already set to 1.7. I reselected 1.7 on all 3 and then Eclipse detected it, asked to rebuild and built my project successfully.

Solution 7 - Java

Window->Preferences->Java->Compiler

select 1.7 and hit okay.

If you are building automatically, it will require a full re-build.

Solution 8 - Java

Right-click on the project. Choose Properties. Choose Java Compiler on the left. Choose 1.7 for the Compiler Compliance level. If the 2 drop-downs below that aren't 1.7, uncheck Use default compliance settings and set those to 1.7.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondorienView Question on Stackoverflow
Solution 1 - JavaEric JablowView Answer on Stackoverflow
Solution 2 - JavaangView Answer on Stackoverflow
Solution 3 - JavaDilanGView Answer on Stackoverflow
Solution 4 - JavaFred Donghwan KimView Answer on Stackoverflow
Solution 5 - JavaDavid B.View Answer on Stackoverflow
Solution 6 - JavaEduardView Answer on Stackoverflow
Solution 7 - JavaPete B.View Answer on Stackoverflow
Solution 8 - Javarajlaxmi_jagdaleView Answer on Stackoverflow