ラムダ式 - 匿名の内部クラス

前jdk1.8:

パブリック クラスTestTow {
     公共 静的 ボイドメイン(文字列引数[]){ 

        TestTow testTow = 新しいTestTow()。

                // 匿名内部类
        INT TEMP = 新しいMathOperation(){ 
            @Override 
            公共 int型の操作は、(int型INT B)は{
                 返す +のBと、
            } 
        } .operation( 2、2 ); 

        System.out.print(TEMP)。

    } 

         // 接口     
    インターフェイスMathOperation {
        INT操作(int型INT B)を、
    } 

}
   

jdk1.8後

パブリック クラスTestTow {
     公共 静的 ボイドメイン(文字列引数[]){ 

        TestTow testTow = 新しい新しいTestTow(); 

        MathOperation mathOperation =(A、B) - > A + B; //ラムダ式と
         int型の TEMP = mathOperation.operation( 4、4 ); //方法、及び伝統的な値呼び出し
        System.out.printの(TEMP); 

    } 

    インターフェースMathOperation {
         int型操作(int型 A、INT Bを); 
    } 

}

 

おすすめ

転載: www.cnblogs.com/zxrxzw/p/12395974.html