lambda expressions - anonymous inner class

jdk1.8 before:

public class TestTow {
    public static void main(String args[]) {

        TestTow testTow = new TestTow();

                //匿名内部类
        int temp = new MathOperation() {
            @Override
            public int operation(int a, int b) {
                return a + b;
            }
        }.operation(2, 2);

        System.out.print(temp);

    }

         //接口    
    interface MathOperation {
        int operation(int a, int b);
    }

}
   

After jdk1.8

public  class TestTow {
     public  static  void main (String args []) { 

        TestTow testTow = new new TestTow (); 

        MathOperation mathOperation = (A, B) -> A + B; // with the lambda expression
         int TEMP = mathOperation.operation ( 4, 4 ); // call the method, and the traditional values 
        of System.out.print (TEMP); 

    } 

    interface MathOperation {
         int Operation ( int A, int B); 
    } 

}

 

Guess you like

Origin www.cnblogs.com/zxrxzw/p/12395974.html