Android Studio: Lambda Does Not Work
Solution 1:
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:
We've decided to add support for Java 8 language features directly into the current javac and dx set of tools, and deprecate the Jack toolchain. With this new direction, existing tools and plugins dependent on the Java class file format should continue to work. Moving forward, Java 8 language features will be natively supported by the Android build system. We're aiming to launch this as part of Android Studio in the coming weeks, and we wanted to share this decision early with you.
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:
... Android Studio 2.1 release includes support for the new Jack compiler and support for Java 8.
With the Jack compiler, lambdas, method references, compile-time type annotations, intersection types and type inference are available on all versions of the Android platform. Default and static methods and repeatable annotations are available on Android N and higher.
To use Java 8 language features when developing with the N Developer Preview, you need to use the Jack compiler. The New Project Wizard [File→ New→ Project] generates the correct configurations for projects targeting the N.
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 use lambdas, one of the major features of Java 8 in Android, you can use gradle-retrolamba
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).
Post a Comment for "Android Studio: Lambda Does Not Work"