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?
Ctrl+Alt+Shift+S (Project Structure icon)
Then change Project language level
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:
File -> Project Structure -> Sources -> Language level
You will have to reload IDEA
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>
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
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>
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
}