I'm having this error when trying to use lambda expressions.
Error:
Error:(122, 42) error: lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)
How can I solve it notice that my android studio is 3.0
Lambda expression is a new and important feature of Java which was included in Java SE 8. It provides a clear and concise way to represent one method interface using an expression. It is very useful in collection library. It helps to iterate, filter and extract data from collection.
Using Lambda Expressions Lambda expressions can be stored in variables if the variable's type is an interface which has only one method. The lambda expression should have the same number of parameters and the same return type as that method.
If you want to replace all the lambda expression from the project you can try Ctrl + Shift+ Alt + I on inspection search tab, search anonymous type can be replaced with lambda. It will replace all the anonymous type to lambda.
It is called lambda expressions, which is a feature of Java 8 and is not yet supported in Android. In your case, it is just the onClick 's View parameter. It is the android studio to compact anonymous inner classes.
Add the below code to your app level gradle:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
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