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.
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:
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.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.
It needs to update the value of "Compiler compliance level" to 1.7 or higher in eclipse. Steps are as below:
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.
Upgrade to Eclipse Mars or latest version Neon :
https://www.eclipse.org/downloads/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With