This question already has an answer here:
When trying to use lambda expressions, I got some Gradle build errors:
Error:(41, 100) error: lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)
Error:Execution failed for task ':app:compileDebugJava'. Compilation failed; see the compiler error output for details.
A quick search helped me understand that lambda expressions are only supported at JDK 1.8, and apparently I am not using it.
My problem is that JDK 1.8 does install on my computer (I am using Yosemite), In module setting → SDK Location → JDK Location it says:
But in Settings module → app → Source/Target Compatibility, there is not an option such as "1.8", there are only options for Java 1.6 or 1.7.
I know I can manage without anonymous functions, but I still want to fix this issue.
Update: 19th June 2017
Jack is now deprecated, and Java 8 support will be integrated to current tools in future. From this blog post Future of Java 8 Language Feature Support on Android:
Update: 26th April 2016
The new version of Android Studio (2.1) has support for Java 8 features. Here is an extract from the Android Developers blogspot post:
Previous answer:
Android does not support Java 1.8 yet (it only supports up to 1.7), so you cannot use lambdas (as one of the comments also mentioned).
This answer gives more detail on Android Studio's compatibility; it states:
If you want to know more about using
gradle-retrolambda
, this answer gives a lot of detail on doing that.Otherwise (and this is probably the best option in my opinion), you will need to go back to using the
anonymous classes
(i.e. how you had it before you changed to using lambda functions).