package com.czie.iot1913.Java8.Lambda.LambdaTest01.Practice02;
/**
* FileName: LamdaDemo02
* Author: lps
* Date: 2022/4/3 21:22
* Sign:刘品水 Q:1944900433
*/
public class LamdaDemo02 {
public static void main(String[] args) {
//useInter(() -> {System.out.println("好好学习 努力奋斗");});
//lambda要求要有接口 且有且仅有一个
useInter(() -> System.out.println("厚积薄发"));
//必须有上下文环境 才能推导出lambda对应的接口
//匿名内部类
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("匿名内部类");
}
}).start();
//根据局部变量的赋值得出对应的接口
Runnable r = () -> System.out.println("Lambda表达式");
new Thread(r).start();
//根据调用方法的参数得出对应的接口
new Thread(() -> System.out.println("表达式")).start();
}
private static void useInter(Inter i) {
i.show();
}
}
package com.czie.iot1913.Java8.Lambda.LambdaTest01.Practice02;
/**
* FileName: Inter
* Author: lps
* Date: 2022/4/3 21:22
* Sign:刘品水 Q:1944900433
*/
public interface Inter {
void show();
//void method();
}