8

I am using JDK 1.8.0. When I import the code into Eclipse I am getting the error:

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

Example:

List<String[]> errors = new ArrayList<>();

I am using Eclipse Kepler.

Draken
  • 3,134
  • 13
  • 34
  • 54
Avinash
  • 81
  • 1
  • 1
  • 3

6 Answers6

14

Sometimes I have seen Eclipse become confused about the Java target version, and throw incorrect messages (even if the project is set up correctly to support Java 7). The easiest way to fix it is to change the target version, then change it back to the expected target version.

This version can be checked by opening the Project properties dialog (right click on the project, and select Properties), and check the settings on two tabs:

  1. Java Compiler tab: Check whether there are any specific settings such as always use a JDK version, etc. By default, all settings here are set to "Use compliance from execution environment 'JavaSE-1.x' on the 'Java build path'." (where x is a Java version). If a specific Java version (pre-Java 7) is selected here, then select the one you are targeting, and you should be done. If the previously mentioned checkbox is set, then follow to step 2.
  2. Java build path tab: Go to libraries, and edit the JRE system library accordingly.

Again, if both settings seem correct, change the latter, rebuild your project (e.g. close your dialog), then change it back and rebuild.

Remarks: if you are using a Maven/Gradle project, it is possible that you should edit these settings in the Maven/Gradle configuration.

Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37
9

It needs to update the value of "Compiler compliance level" to 1.7 or higher in eclipse. Steps are as below:

  1. Open project in eclipse
  2. Right click on Project and go to Properties
  3. In Properties panel: click "Java Compiler" at the left and update the value of "Compiler compliance level" to 1.7 or higher from the drop down.
  4. Click Apply and OK button enter image description here
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
6

Add this to your pom.xml, below <project>.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Most likely it's the default Eclipse Maven configuration that set your project's JDK version to 1.5 - God knows why. This will set it to 1.8 instead.

Hung Luong
  • 166
  • 1
  • 10
1

Upgrade to Eclipse Mars or latest version Neon :

https://www.eclipse.org/downloads/

Chirag Parmar
  • 833
  • 11
  • 26
0

Inserting 8 in the section of the pom (maven) helped in my case.

-2

Try the followings:

List<String[]> errors = new ArrayList();

OR,

List<String[]> errors = new ArrayList<String[]>();

Or, change your project Compiler compliance level to 1.7 or higher in Eclipse.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
ansanes
  • 87
  • 1
  • 9