Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Lambda expressions are not allowed at this language level

I am working on a chat application. I got a demo app from github, the chat app that is working. In some classes they used lambda expressions but it's working fine, but when I copy those code mine is giving this error " Lambda expressions are not allowed at this language level ". Some people said that android studio does not support lambda expressions but the demo app is working on my phone.

like image 567
Abdurakhmon Avatar asked May 01 '17 16:05

Abdurakhmon


People also ask

Which of the following is are not valid lambda expressions?

Based on the syntax rules just shown, which of the following are not valid lambda expressions? Answer: Only 4 and 5 are invalid lambdas.

Does Android support Java 8?

Android Gradle plugin 3.0. 0 and later support all Java 7 language features and a subset of Java 8 language features that vary by platform version. When building your app using Android Gradle plugin 4.0. 0 and higher, you can use a number of Java 8 language APIs without requiring a minimum API level for your app.

How to enable lambda expression in intellij?

Select project and press alt+ctrl+shift+s and you get Project Structure window where you need to set project sdk and language level for project. Then you should be able to use lambdas.

Does Groovy support lambda?

The Groovy syntax doesn't support the lambda expressions, but we can rely on closure coersion to use Groovy closures as Java lambda expressions in our code. In the following sample we use the Java Streams API. Instead of lambda expressions for the filter and map methods we use Groovy closures.


1 Answers

in build.gradle there should be

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

And you should probably use RetroLambda. Look at the demo project's build.gradle file

like image 136
xorgate Avatar answered Sep 27 '22 18:09

xorgate