54

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.

dorien
  • 5,265
  • 10
  • 57
  • 116

8 Answers8

95

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.

Eric Jablow
  • 7,874
  • 2
  • 22
  • 29
  • 1
    I reinstalled the oracle jdk. In preferences -> JRE environments I manually added the path to the jde, then in preferences->compiler-> I indeed changed the compliance level (I think that was missing). Thanks so much! – dorien Oct 15 '13 at 13:34
  • 1
    I am using "PlayHaven Android SDK"... doing so gave me new problem... Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties. Still wondering how did they compiled it. :O – jeet.chanchawat Apr 25 '14 at 06:11
  • 2
    This answer worked for me, but I had to perform one additional step: Clean your project BEFORE rebuilding! This may be a no brainer to most, but I figured it could save some people a few extra minutes of time if they are anything like me. I tried building before cleaning, and was still getting the above error. – user972276 Jun 30 '14 at 21:03
  • I'm using v23 of tools - still see this behavior. For me, I realized it is because new messages are being added to LogCat, EVEN THOUGH they are filtered out. Whenever adb logcat gets a new message, my scroll area jumps to the bottom, even though it does not display the messages because they are filtered out. – Colin Oct 20 '14 at 19:01
  • @jeet.chanchawat have you find solution for that problem? – sud Dec 08 '15 at 07:17
  • what if i am getting this error when updated from using Java 1.7 to Open JDK 11 ? – prnjn Mar 29 '19 at 10:24
30

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

ang
  • 679
  • 7
  • 10
  • 1
    Thank you, thank you and thank you. after trying lot of options that ultimately lead me no-man land, this ulitmately saved me, removed hundreds of errors in a one or two clicks. – AKS Dec 02 '14 at 09:59
6

If you want to use below version, use

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

instead of

HashMap<String, Integer> map = new HashMap<>();
CSchulz
  • 10,882
  • 11
  • 60
  • 114
DilanG
  • 1,197
  • 1
  • 26
  • 42
4

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

  • This doesn't see to add anything new to the existing (accepted) [answer](http://stackoverflow.com/a/19382561). – Artjom B. Sep 29 '15 at 19:47
0

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.

David B.
  • 135
  • 1
  • 8
0

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.

Eduard
  • 167
  • 1
  • 12
0

Window->Preferences->Java->Compiler

select 1.7 and hit okay.

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

Pete B.
  • 3,188
  • 6
  • 25
  • 38
0

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.

rajlaxmi_jagdale
  • 1,370
  • 15
  • 16