From Http://www.coshx.com/blog/2015/03/23/use-java-8s-lambda-functions-in-android/using Java in Android 8 lambda Expressions As a Java developer, you may often have a lot of trouble with the closeness of your information. Fortunately: Java's 8th version introduced lambda functions brings us good news; however, there are some eggs, on Android, we can still use only Java7. So what's the situation now? Haha, we can use Android Developer! Our old buddy Esko Luontola found a way to use lambda on Android, which is awesome! So, let's see how it's going to come true! Just as there is Retroweaver et al. for running Java 5 Code with generics on Java 1.4. RETROLAMBDA allows us to use lambda expressions on Java 8 or lower. This is great: in Java 7 virtual machines, we are able to run code compiled on 8. Now, we use Android Studio and Gradle to achieve it, and RETROLAMBDA signed a contract to become a horse monkey burning Bar (fog!). Install the Java 8 SDK, as long as you want to use the Java 8 SDK, here to download: Java 8 OK, now in Android studio to set up the use of Java 8 bar.
Mac:
File > Project structure. You need to set this up:
Other settings can be referenced.
Set up gradle you're awesome! You're almost ready. The final step is to edit some of the Gradle's configuration files. We will use Retrolambda plugin from Evan Tatarka to support lambda expressions. First, open the Build.gradle file in the app module and change the configuration under the Compileoption node:
android { } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }}
Second, add in the same file:
buildscript { repositories { mavenCentral() } dependencies { classpath ‘me.tatarka:gradle-retrolambda:2.5.0‘ }}repositories { mavenCentral()}apply plugin: ‘me.tatarka.retrolambda‘
Then just OK, try to build your project, it must be awesome ~
It is important to note that RETROLAMBDA only allows you to use lambda expressions in Java 8, and that other features do not work in Android.
Using a lambda expression in Java 8 in Android