package com.threehigh.lambda;
@FunctionalInterface
public interface IGreeting {
void sayHello(String message);
}
package com.threehigh.lambda;
@FunctionalInterface
public interface IMathOperation {
int operation(int a,int b);
}
package com.threehigh.lambda;
public class LambdaSyntaxTest {
public static void main(String[] args) {
IMathOperation mo = (int a,int b) -> {
return a + b;
};
System.out.println(mo.operation(22, 33));
System.out.println("--------------------------");
IGreeting greeting = (String msg) -> System.out.println("hello " + msg);
greeting.sayHello("Lambda表达式");
System.out.println("--------------------------");
greeting = message -> System.out.println("hello again " + message);
greeting.sayHello("Lambda表达式33 ");
System.out.println("--------------------------");
IMathOperation m2 = (int a,int b) -> a - b;
System.out.println(m2.operation(6, 4));
System.out.println("--------------------------");
IMathOperation m3 = (a,b) -> a * b;
System.out.println(m3.operation(6, 4));
}
}
55
--------------------------
hello Lambda表达式
--------------------------
hello again Lambda表达式33
--------------------------
2
--------------------------
24