好傢伙呀,原來這個符號這樣讀的,讀了幾年的Lambda了。java
爲何要用Lambda表達式express
public class TestLambda { //3.靜態內部類 static class Like2 implements ILike{ @Override public void lambda(){ System.out.println("This is lambda2!"); } } 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("This is lambda3!"); } } like = new Like3(); like.lambda(); //5.匿名內部類,類沒有接口,直接利用接口或者父類 like = new ILike() { @Override public void lambda() { System.out.println("This is lambda4!"); } }; like.lambda(); //6.用lambda簡化 like = () -> { System.out.println("This is lambda5!"); }; like.lambda(); } } //1.定義一個函數式接口 interface ILike{ void lambda(); } //2.實現類 class Like implements ILike{ @Override public void lambda(){ System.out.println("This is lambda!"); } }
這裏有幾個關鍵的地方:編程
首先接口,若是隻包含一個抽象方法。多線程
用接口來定義對象。ide