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 ?
In Android Studio (File -> Project Structure..., Properties tab), set the following values:
Source Compatibility == 1.7
Target Compatibility == 1.7
After this your build.gradle will have these entries:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With