Android Lambda

到目前为止 android 本身不支持lambda语法, 但Java的JDK1.8+支持lambda,故我们可以稍做修改,让android支持lambda,以AS为例

1. 确保你的JDK是1.8及以上的

2.在AS的工程配置文件build.gradle中的buildscript里加入

dependencies { 

    classpath 'me.tatarka:gradle-retrolambda:3.1.0'

}

3.在模块工程配置文件build.gradle中加入

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

OK, 这样android就支持lambda了。

 

posted @ 2016-02-18 11:38  半凉半夏  阅读(745)  评论(0编辑  收藏  举报