packageexception.lambda;/*
推导lambda表达式,
*/publicclassTestLambda1{//3、静态内部类staticclassLike2implementsILike{@Overridepublicvoidlambda(){System.out.println("I like lambda2!");}}publicstaticvoidmain(String[] args){ILike like =newLike();
like.lambda();
like =newLike2();
like.lambda();//4、局部内部类classLike3implementsILike{@Overridepublicvoidlambda(){System.out.println("I like lambda3!");}}
like =newLike3();
like.lambda();//5、匿名内部类,没有类的名称,必须借助接口或者父类
like =newILike(){@Overridepublicvoidlambda(){System.out.println("I like lambda4!");}};
like.lambda();//6、用Lambda简化
like =()->{System.out.println("I like lambda5!");};
like.lambda();}}//1、定义了一个函数接口interfaceILike{voidlambda();}//2、实现类classLikeimplementsILike{@Overridepublicvoidlambda(){System.out.println("I like lambda!");}}
packageexception.lambda;publicclassTestLambda2{publicstaticvoidmain(String[] args){classLoveimplementsILove{@Overridepublicvoidlove(int a){System.out.println("I love you!!!-->"+a);}}ILove love =(int a)->{System.out.println("I love you!!-->"+a);};
love.love(520);};}interfaceILove{voidlove(int a);}