package basic.lambda; public class Feature { // å¯éç±»å声æ - æ é声æåæ°çç±»åãç¼è¯å¨å¯ä»¥ä»è¯¥åæ°ç弿¨æã // å¯é忬å·åæ° - æ é卿¬å·ä¸å£°æåæ°ã对äºå¤ä¸ªåæ°ï¼æ¬å·æ¯å¿ éçã // å¯é大æ¬å· - 表达å¼ä¸»ä½æ²¡æå¿ è¦ä½¿ç¨å¤§æ¬å·ï¼å¦æä¸»ä½ä¸å«æä¸ä¸ªåç¬çè¯å¥ã // å¯éreturnå ³é®å - ç¼è¯å¨ä¼èªå¨è¿åå¼ï¼å¦æä¸»ä½æä¸ä¸ªè¡¨è¾¾å¼è¿åçå¼ãè±æ¬å·æ¯å¿ éçï¼ä»¥è¡¨æè¡¨è¾¾å¼è¿åä¸ä¸ªå¼ã public static void main(String[] args) { Feature ft = new Feature(); // with type declaration MathOperation addition = (int a, int b) -> a + b; // with out type declaration MathOperation subtraction = (a, b) -> a - b; // with return statement along with curly braces MathOperation multiplication = (int a, int b) -> { return a * b; }; // without return statement and without curly braces MathOperation division = (int a, int b) -> a / b; System.out.println("10 + 5 = " + ft.operate(10, 5, addition)); System.out.println("10 - 5 = " + ft.operate(10, 5, subtraction)); System.out.println("10 x 5 = " + ft.operate(10, 5, multiplication)); System.out.println("10 / 5 = " + ft.operate(10, 5, division)); // with parenthesis GreetingService greetService1 = message -> System.out.println("Hello " + message); // without parenthesis GreetingService greetService2 = (message) -> System.out .println("Hello " + message); greetService1.sayMessage("Mahesh"); greetService2.sayMessage("Suresh"); } interface MathOperation { int operation(int a, int b); } interface GreetingService { void sayMessage(String message); } private int operate(int a, int b, MathOperation mathOperation) { return mathOperation.operation(a, b); } }