package Lambda;
public class Demo1 {
//静态内部类
static class Like2 extends Like{
public void lambda(){
System.out.println("I like lambda2");
}
}
public static void main(String[] args) {
//1、正常调用
ILike like = new Like();
like.lambda();
ILike like2 = new Like2();
like2.lambda();
//2、局部内部类
class Like3 extends Like{
public void lambda(){
System.out.println("I like lambda3");
}
}
ILike like3 = new Like3();
like3.lambda();
//3、匿名内部类
ILike like4 = new ILike(){
@Override
public void lambda(){
System.out.println("I like lambda4");
}
};
like4.lambda();
//4、lambda简化,单方法接口的匿名实现类
ILike like5 = ()->{
System.out.println("I like lambda5");
};
like5.lambda();
}
}
interface ILike{
void lambda();
}
class Like implements ILike{
@Override
public void lambda(){
System.out.println("I like lambda");
}
}
标签:like,void,ILike,System,简化,Lambda,public,表达式,lambda
From: https://www.cnblogs.com/sy19931020/p/16592058.html