# Android's Java 9, 10, 11, and 12 Support

DevFeed: [Android's Java 9, 10, 11, and 12 Support](<https://devfeed.tech/articles/android-s-java-9-10-11-and-12-support-20918.md>)

Original publisher: [Read original article](<https://jakewharton.com/androids-java-9-10-11-and-12-support/>)

Published: 2018-11-27T00:00:00Z

Content type: article

Language: en

Sources: [Jake Wharton](<https://devfeed.tech/sources/jake-wharton.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Android](<https://devfeed.tech/topics/android.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [java](<https://devfeed.tech/tags/java.md>), [toolchain](<https://devfeed.tech/tags/toolchain.md>)

## AI overview

This article examines Android support for Java releases beyond Java 8, focusing on how the Android toolchain handles Java 9, 10, 11, and 12 language features. It explains that some Java 9 features are implemented by the Java compiler and can be processed by D8 for all Android API levels.

## Source excerpt

Note: This post is part of a series on D8 and R8, Android's new dexer and optimizer, respectively. For an intro to D8 read "Android's Java 8 support". The first post in this series explored Android's Java 8 support. Having support for the language features and APIs of Java 8 is table stakes at this point. We're not quite there with the APIs yet, sadly, but D8 has us covered with the language features. There's a future promise for the APIs which is essential for the health of the ecosystem. A lot of the reaction to the previous post echoed that Java 8 is quite old. The rest of the Java ecosystem is starting to move to Java 11 (being the first long-term supported release after 8) after having toyed with Java 9 and 10. I was hoping for that reaction because I mostly wrote that post so that I could set up this one. With Java releases happening more frequently, Android's yearly release schedule and delayed uptake of newer language features and APIs feels more painful. But is it actually the case that we're stuck with those of Java 8? Let's take a look at the Java releases beyond 8 and see how the Android toolchain fares. Java 9 The last release on the 2 - 3 year schedule, Java 9 contains a few new language features. None of them are major like lambdas were. Instead, this release focused on cleaning up some of the sharp edges on existing features. Concise Try With Resources Prior to this release the try-with-resources construct required that you define a local variable (such as try (Closeable bar = foo.bar())). But if you already have a Closeable, defining a new variable is redundant. As such, this release allows you to omit declaring a new variable if you already have an effectively-final reference. import java.io.*; class Java9TryWithResources { String effectivelyFinalTry(BufferedReader r) throws IOException { try (r) { return r.readLine(); } } } This feature is implemented entirely in the Java compiler so D8 is able to dex it for Android. $ javac *.java $ java -jar d8.