Java- Diamond types are not supported at this language level

26.5k views Asked by At

I have just started working on a Java project, and have downloaded the source code from GitHub, using IntelliJ- I have never used IntelliJ before, but am told that it is a much better IDE to use than Eclipse (which is what I was using when I last did any Java development- about four years ago).

When I try to build the source locally on my computer, having pulled the latest working version from GitHub, I get a compile error on several different lines of code- the error says:

Error:(27, 34) java: diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)

and the lines where these compile errors appear, are lines like:

return new ArrayList<>(0);

If I select the line, and do Alt + Enter on the error, it shows a message stating that I can

"Set language level to 7- Diamonds, ARM, Multi-cache, etc"

However, if I select this option, nothing happens...

In the pom.xml file, there is the following xml:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>${maven-source-plugin.version}</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

But when I looked this error up, I came across the answer at: Diamond type are not supported at this language level, which indicated that I should be using maven1.7 or higher- and it appears that the project is already using version 1.8, so I don't understand why I'm getting this compile error...

Anyone have any suggestions?

2

There are 2 answers

0
user8936069 On BEST ANSWER

Add the following code into your pom.xml file.

<!-- maven-compiler-plugin -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
5
DrLime2k10 On

Under File->Project Structure (Ctrl + Alt + Shift + s) there's a section called Project Settings, and Project

Here you can set the project language level. enter image description here