Diamond type is not supported at this language level

After importing the project into Android studio, if I want to compile or run the project, it gives an error:

Error: (61, 65) java: diamond operator is not supported in source 1.6
(use source operator 7 or higher to enable the diamond operator)

Does anyone know what it is and how to solve it?

+7
android android-studio diamond-operator
source share
6 answers

In Android Studio (File β†’ Project Structure ..., Properties tab), set the following values:

Source Compatibility == 1.7 Target Compatibility == 1.7 

enter image description here

After that, your build.gradle will have the following entries:

 compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } 

enter image description here

+12
source share

In Intellij Idea you need to set the language level of the project (the default for all modules) and the language level (s) of the module.

File β†’ Project structure β†’ In the Project settings section β†’ Select Project β†’ Project language level β†’ Select 7 - Diamons, ARM, multi-catch, etc. or 8 - Lambdas, type annoationsetc . and click Apply

Click here to see the pic

+7
source share

A few days ago I suffered from this. Just update buildToolsVersion as shown below. And update your SDK .

  android { compileSdkVersion 21 buildToolsVersion '21.1.2' defaultConfig { minSdkVersion 15 targetSdkVersion 19 versionCode 1 versionName "1.0" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } 
+2
source share

The diamond operator is one of the new features of Jdk 7. Please make sure you have jdk version 7 or not. Here is an example of a diamond operator.

Here is the assignment operator:

 Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); 

With a diamond operator:

 Map<String, List<String>> anagrams = new HashMap<>(); 

Edit

Add this to your build.gradle ..

 android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } 

Hope this will be helpful for you.

+2
source share

Using Android KitKat (buildToolsVersion 19), you can use the diamond operator, multi-user mode, lines in switches, try with resources, etc. To do this, add the following file to the assembly file:

 android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 19 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } 

Note that you can use minSdkVersion with a value earlier than 19, for all language functions except try with resources. If you want to use try with resources, you will also need to use minSdkVersion 19.

You also need to make sure that Gradle is using version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin.)

http://tools.android.com/tech-docs/new-build-system/user-guide

+1
source share

In Intellij, for me, the problem was that the target version for each module, indicated in the section "Settings-> Build, Run, Deploy-> Java Compiler", was incorrect. enter image description here

Hope this helps someone.

+1
source share

All Articles