简易的Lambda练习

第十周 将下列程序改写为Lambda表达式

interface Cry{
    public void cry();
}
public class Test{
    public static void main(String args[]){
        Cry hello=new Cry(){
            public void cry(){
                System.out.println("大家好,祝工作顺利!");
            }
        };
        hello.cry();
    }
}

使用了接口打印一段语句,改写lambda时只要去掉括号及函数的名字使用 ()->语句

interface Cry{
    public void cry();
}
public class Main10 {
    public static void main(String[] args) {

        Cry hello = () -> System.out.println("大家好,祝工作顺利!");
        hello.cry();
    }
}
posted @ 2021-07-09 20:30  SKPrimin  阅读(30)  评论(0编辑  收藏  举报