Android N, Java8, and Kotlin

News! Google is adopting Java8 for Android N alongside their new “Jack” compiler infrastructure. This raises an obvious set of questions for how Kotlin will interoperate with this (e.g., how Kotlin lambdas can be passed to Java8 and vice versa). My observation playing with this a while ago, with vanilla Java8 were that Java8 lambdas and Kotlin lambdas don’t have the same type, which can get a bit klunky.

I haven’t dug through the new Android N APIs yet, but I’m assuming that they’re still built with old-Java (so no default methods, no lambdas), but in the next year or two, you can expect that to start changing.

1 Like

Yeah, the lack of standard lambda interface types is really unfortunate. Kotlin/Scala/etc have their own FunctionN interfaces, Java has a zoo of random names (whyyyyyyyyy). This seems super unfortunate. It should not have been hard for everyone to standardise on lambda functional interfaces but it seems the JVM ecosystem has managed to screw this up :frowning:

It might make sense for a future Kotlin version that targets Java 8 to be able to use the Java 8 functional interfaces when usable (with the name mapping inside the compiler), but of course it is a binary compatibility break.

1 Like

Impressive news… Though, I would really like to know more about the compatibility with the new android compiler, jack & jill.
I understand that kotlin can use jill to still be compatible with this new compiler, but at the cost of some compile speed.
Would there be any for Kotlin to integrate to the Jack compiler (by working with Android team of course) ?

Btw, some infos here : Android N Java 8 features (Jack compiler) and Kotlin interop - Stack Overflow

AFAIU, Android N tools supports Java 8 via the Jack compiler, which enables lambdas via anonymous classes, not InvokeDynamic.
It looks unlikely that even Jack would support JVM 8 bytecode.
Furthermore, the Java 8 Stream API is not included in Android N. So it looks like Jack really works just like retro-lambda.

As for Java 8 function interfaces, the Kotlin compiler already does a pretty good job in transforming Kotlin function objects into Java 8 SAM interfaces.

Java 8 interoperability is a very important milestone for Kotlin, but It doesn’t look like it’s going to be important for Android N…

1 Like