52

I' trying to build a in IntelliJ IDEA project that is not mine and I got the following error:

java: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator)

How do I change this setting in IntelliJ IDEA?

El Marce
  • 2,962
  • 1
  • 22
  • 38

7 Answers7

71

Ctrl+Alt+Shift+S (Project Structure icon)

Then change Project language level

Ori Dar
  • 18,079
  • 5
  • 53
  • 67
26

I know the OP uses IntelliJ IDEA, but Android Studio is based on IntelliJ IDEA, so I wanna say one more word.

If you use Android Studio, command+;(for Mac) or File->Project Structure, then in the open window follow the settings:

enter image description here

Allen
  • 6,637
  • 5
  • 40
  • 56
21

And, if you're working with a maven project, for sanity, remember to set the java version in the pom too.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Sarah Phillips
  • 903
  • 11
  • 29
17

File -> Project Structure -> Sources -> Language level

You will have to reload IDEA

senseiwu
  • 4,617
  • 5
  • 23
  • 45
10

File->Project structure->Project Settings->Modules->Language level

Change level using drop down.

Otherwise, If you are using maven for build,

<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>
ketankk
  • 2,452
  • 1
  • 25
  • 26
6

For me, changing the Language Level in Project Structure and restarting IDEA didn't help.

I had to edit the build.gradle in core module and change the source compatibility from 1.6 to 1.7:

apply plugin: "java"

sourceCompatibility = 1.7 //changed from 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"
}

Build -> Clean Project

Neerkoli
  • 2,135
  • 3
  • 15
  • 21
1

For me, above answers didn't work, although they helped me solve my issue. At module level build.gradle do the following:

compileOptions {
        // I've changed below values from VERSION_1_6 to VERSION_1_7
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
NecipAllef
  • 447
  • 1
  • 4
  • 16