Skip to main content

Posts

Showing posts from 2016

How to use Java8 in Android Studio

Java 8 has one very attractive feature I want to use, which is lambda expression. In Android code, we often use anonymous interface to assign event listener such as button. Java's lambda is not quite powerful comparing to other languages support lambda expression but still useful. You can check the information in detail at: https://developer.android.com/guide/platform/j8-jack.html#configuration To use Java 8 feature, you need to download & install Android N(Android 7.0, API level 24).  Android doesn't support all Java8 features:  Default and static interface methods  Lambda expressions (also available on API level 23 and lower)  Repeatable annotations  Method References (also available on API level 23 and lower)  Type Annotations (also available on API level 23 and lower)   You have to config your project Gradle build file. It should be like following: apply plugin : 'com.android.application' android { compileSdkVersion 24 buildToolsVers