Native Java 8 arrives on android! Finally!
Starting with Android Studio 2.4 Preview 4 and android gradle plugin version 2.4.0-alpha4, Java 8 language features are now natively supported by android:
- Lambda expressions;
- Method references
- Type annotations (currently type annotation information is not available at runtime but only on compile time);
- Repeating annotations;
- Default and static interface methods (on API level 24 or higher, no instant run support tho);
Also from min API level 24 the following Java 8 API are available:
The Android team promised that more Java 8 features are going to be added in the future.
How can I enable this then?
Add the following to your project’s main build.gradle:
Add these lines to your application module’s build.gradle to inform the project of the language level:
You’re done! You can now use native java8!
For more details visit: