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:
You have to config your project Gradle build file. It should be like following:
- 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 buildToolsVersion "24.0.2" defaultConfig { ... jackOptions { enabled true } } buildTypes { ... } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.1' testCompile 'junit:junit:4.12' }
Comments
Post a Comment