Ysch Ysch - 3 months ago 11
Android Question

Android and Lambda

I need to integrate some code with extensive usage of Java lambda functions.
Several restrictions I have demand that I develop my project using Eclipse Mars, with the latest ADT plugin, and not Android Studio.

The problem is that using Lambda functions demands using 1.8 JDK compliance, but if set so, I get this message:

Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead.

How can the two live together in harmony?

This is not a a duplicate of the questions suggested, as I'm asking about ADT Eclipse, and since the last update in that question, Android does support Java 8, so no only is this not a duplicate, but that question is now (after 1.5 yrs after the last update) obsolete.


As @dhke said, there's no support for Java 8 on Android yet.

Use Java 8, Build For Java 6/7

But you can still use JDK 8 to develop Android application. You just need to set source compatibility to either 6 or 7 depends on your minSDKVersion. Thus, you would lose any new features introduced in Java 8, like lambda in your case.

Backport of Lamda

Since you have extensive usage of lambda, Retrolambda might be an option for you. It provides backport of lambda for pre-Java 8 versions. It has Maven/Gradle/command line plugin to enable the support.

Other Backports

If you need other Java 8 features, AFAIK, ThreeTen ABP provides backport support for Java 8 Date Time API.