1

Does IntelliJ Android Studio last update (From 30/Jan/2016) supports Java 8?

I used a lambda expression

mButton.setOnClickListener((View v) -> {
    // do something here
});

then Android Studio tells me I have an error and when I resolve the problem (Alt+spacebar) I choose the Change to Java 8 (or something like that) and it works the lambda but the libraries from Android seems to be unsupported it marks all in red.

Any options for supporting Java 8 in Android Studio?

Note: I'm using the last API Level

Horacio Garza
  • 45
  • 2
  • 7

2 Answers2

5

No, Java 8 isn't supported. What you can do instead to write Lambdas and method references is to include retrolambda dependency to your project. Same with streams, here is a backport library. Alternatively, consider using kotlin.

dawid gdanski
  • 2,432
  • 3
  • 21
  • 29
  • 1
    @HoracioGarza Just wanted to add, that for Java 8 streams, there is also the [streamsupport library](https://sourceforge.net/projects/streamsupport/) which is much closer to Java 8 Stream syntax and functionality than the [Lightweight-Stream-API](https://github.com/aNNiMON/Lightweight-Stream-API). For example, it also supports parallel streams. – Sartorius Aug 20 '16 at 14:18
1

Android is using the retired Apache Harmony as its Java implementation and I believe Harmony is on Java 6, so no, Java 8 is not supported.

Java 8 will be supported in Android N though as it will use OpenJDK instead of Harmony.

Korpen
  • 68
  • 7