Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diamond type are not supported at this language level

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

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

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

like image 329
Amir Avatar asked Mar 23 '15 07:03

Amir


3 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 this your build.gradle will have these entries:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

enter image description here

like image 148
erajuan Avatar answered Oct 17 '22 23:10

erajuan


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

File --> Project Structure --> Under Project Settings --> Select Project --> Project Language Level --> Select 7 - Diamons, ARM, multi-catch etc. or 8 - Lambdas,type annoationsetc. option and Click on Apply

Click here to see the pic

like image 7
Ranga Reddy Avatar answered Oct 17 '22 23:10

Ranga Reddy


Diamond operator is one of the new feature of Jdk 7. Please make sure you jdk version is 7 or not. Here is an example of diamond operator.

Here is an assignment statement :

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

With diamond operator :

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

Edit

Add that 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 it will be useful for you.

like image 2
Arkar Aung Avatar answered Oct 17 '22 23:10

Arkar Aung