Android N Feature Spotlight: Notification Shade Now A Lot More Powerful With Direct Reply And Notification Bundling
Android N Feature Spotlight: Split-Screen Multitasking And Picture-In-Picture Mode Finally Come To Android
Android N Feature Spotlight: Jack Compiler Gains Support For Many Java 8 Language Features Including Lambdas, Streams, Functional Interfaces, And More
[Download] Here's The New Android N Wallpaper
Android N Feature Spotlight: The New Quick Settings Menu Includes Mini-Toggles And Easy Editing
- View All 92 Articles In This Series
Developers have plenty of great new APIs and features coming with Android N, but perhaps the best thing to look forward to is at the language level itself. Starting with the preview SDK due out today, some of the language features of Java 8 will be supported by the Jack compiler. This will bring things like support for lambdas, default and static methods, streams, and functional interfaces. Google is also declaring that the Jack compiler will also be able to remain more up-to-date with Java language features in the future.
One of the top requests from developers over the last few years has been for a more rapid uptake of new language features for Java, many of which would allow for more efficient use of development time and ultimately easier to read code. Android originally launched with support for Java 6, but over the years, Google has introduced support for many of the language features in Java 7. In Android 5.0 Lollipop, Java 7 was even made a requirement. Through workarounds and hacks, a few of the more modern features could be used, but it's hard to beat first-party support.
The feature most developers have been clamoring over is support for lambda expressions. While we've been able to use anonymous classes for a while, the syntax is pretty clunky and doesn't lend itself very well to reading outside of an IDE like Android Studio. With lambdas, a much cleaner, more simplified syntax can be used. This will be a welcome improvement, particularly for UI code where event handlers tend to get cluttered up with the excess code required for anonymous inner classes. Code written with lambda expressions will work on Android versions as far back as Gingerbread, so it should be perfectly suitable for almost any current project.
Also joining the list of new language features are default and static methods, streams, and functional interfaces. All of these are notably helpful in either simplifying difficult-to-write functionality or cutting down on the amount of code to perform a specific type of task. The limitations on these features are unfortunately much stricter than those of lambdas—they will only work on Android N and above. In other words, they're effectively off limits for now.
Google credits the Jack compiler for making faster progress with the Java 8 and suggests that it will allow for keeping up with modern language features at a faster rate. From the sound of it, we can probably expect to see announcements like this one with just about every release of Android in the foreseeable future. In fact, with the rate things have been moving with the Android Tools Team, we may even see a few mid-cycle additions for features that won't strictly require capabilities built directly into the OS.
To take advantage of these new features, you'll need to get a few things downloaded and installed. If you don't already have JDK 8 (and JRE 8, as well), those may be the first things on the list to get. While those are downloading, get started on updating Android Studio to v2.1 Preview 1, which just came out to the canary channel today. Finally, there's a brand new SDK to download for the N Developer Preview, which can be updated through the SDK Manager. Yep, there's a lot of downloading to do, so get started. Complete instructions are available at the link below.
- Android Developer Portal