- Lambda表达式只支持接口。
- Lambda表达式不能简化抽象类。
-
/** * Lambda 表达式 *@author asus *@date 2022/6/21 */ public class Lambda { public static void main(String[] args) { People people = new People() { @Override public void run() { System.out.println("跑得快**************"); } }; people.run(); //Lambda 表达式 People people1 = () -> { System.out.println("跑得快**************"); }; people1.run(); } } @FunctionalInterface //函数式接口,加上该注解后,一个接口中只能有一个方法 interface People{ void run(); }
04-25
326
