new Thread(()->System.out.println("多线程学习")).start();
lambda表达式只能有一行代码的情况下才可以简化成一行,如果有多行,就需要用代码块
必须是函数式接口接口(函数式接口就是只包含唯一一个抽象方法)
多个参数可以去掉参数类型,要去掉就必须都去掉,然后变量名就必须要括号
package com.thread; public class TestThread4 { //3.静态内部类 static class Like2 implements Ilike{ @Override public void lambda() { System.out.println("I like study2"); } } public static void main(String[] args) { Ilike like = new Like(); like.lambda(); like=new Like2(); like.lambda(); //4.局部内部类 class Like3 implements Ilike{ @Override public void lambda() { System.out.println("I like study3"); } } like=new Like3(); like.lambda(); //5.匿名内部类 like=new Ilike() { @Override public void lambda() { System.out.println("I like study4"); } }; like.lambda(); //6.lambda简化 like=() ->{ System.out.println("I like study5"); }; like.lambda(); } } //1.定义一个接口 interface Ilike{ void lambda(); } //2.实现接口类 class Like implements Ilike{ @Override public void lambda() { System.out.println("I like study"); } }