lambda
package demo02;
public class TestLambda1 {
//实现类换为静态内部类
//2.实现类
static class Like2 implements IlIKE{
@Override
public void lambda() {
System.out.println(" I like lambda2");
}
}
public static void main(String[] args) {
IlIKE ilIKE=new Like();
ilIKE.lambda();
new Like2().lambda();
//局部内部类
class Like3 implements IlIKE{
@Override
public void lambda() {
System.out.println(" I like lambda3");
}
}
new Like3().lambda();
//匿名内部类
ilIKE = new IlIKE() {
@Override
public void lambda() {
System.out.println("I like lambda4");
}
};
ilIKE.lambda();
//lambda简化
ilIKE = ()->{
System.out.println("I like lambda5");
};
ilIKE.lambda();
}
}
//1.定义函数式接口
interface IlIKE{
void lambda();
}
//2.实现类
class Like implements IlIKE{
@Override
public void lambda() {
System.out.println(" I like lambda");
}
}