1.Project build.gradle 添加插件下载路径
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
2.项目模块运用插件
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
3.在模块build.gradle 的 android里头添加申明java8
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
使用Lambda
()->{}//小括号写内部方法名,大括号写方法体,如果只有一句可以省略大 括号
view1.setOnClickListener(
(v)-> Toast.makeText(this, "哈哈", Toast.LENGTH_SHORT).show());
new Thread(()->{}).start();//开启线程
单方法调用使用:: view1.setOnClickListener(this::click);