lambda functions programming

 

 

This paragraph is an excerpt from Notes: Rookie Tutorial

                public class Test 
                 {

                /*
                     
      
                            Lambda 表达式,也可称为闭包,它是推动 Java 8 发布的最重要新特性。
                            Lambda 允许把函数作为一个方法的参数(函数作为参数传递进方法中)。
                            使用 Lambda 表达式需要注意以下两点:
                                   1. Lambda 表达式主要用来定义行内执行的方法类型接口。
                                   2. Lambda 表达式免去了使用匿名方法的麻烦,并且给予Java简单但是强大的函数化的编程能力。
      
                */  



                /* 编写接口的方式不变 */ interface GreetingService { void AddMethodByPram(int a, int b); } /* 最后调用接口的方法传入实参 */ public static void main(String args[]) { GreetingService greetingService1 = (a, b) -> System.out.println(a + b); greetingService1.AddMethodByPram(1,6); } /* 博主温馨提示:请在jdk1.8版本的Project上使用,否则编译不通过 个人理解: 1. -> 类似于代码块括号。 2. greetingService1 类似于实例化对象的引用。 3. (a,b) 作为形参直接传入接口中的方法。 4. System.out.println(a + b) 是接口实现后具体的行为。 */ }

Examples of relatively simple, in fact, I am not good at describing, but will gradually improve.
For the first time to write and share study notes, subject to errors and omissions, bear with me.

This paragraph is an excerpt from Notes: Rookie Tutorial

                public class Test 
                 {

                /*
                     
      
                            Lambda 表达式,也可称为闭包,它是推动 Java 8 发布的最重要新特性。
                            Lambda 允许把函数作为一个方法的参数(函数作为参数传递进方法中)。
                            使用 Lambda 表达式需要注意以下两点:
                                   1. Lambda 表达式主要用来定义行内执行的方法类型接口。
                                   2. Lambda 表达式免去了使用匿名方法的麻烦,并且给予Java简单但是强大的函数化的编程能力。
      
                */  



                /* 编写接口的方式不变 */ interface GreetingService { void AddMethodByPram(int a, int b); } /* 最后调用接口的方法传入实参 */ public static void main(String args[]) { GreetingService greetingService1 = (a, b) -> System.out.println(a + b); greetingService1.AddMethodByPram(1,6); } /* 博主温馨提示:请在jdk1.8版本的Project上使用,否则编译不通过 个人理解: 1. -> 类似于代码块括号。 2. greetingService1 类似于实例化对象的引用。 3. (a,b) 作为形参直接传入接口中的方法。 4. System.out.println(a + b) 是接口实现后具体的行为。 */ }

Examples of relatively simple, in fact, I am not good at describing, but will gradually improve.
For the first time to write and share study notes, subject to errors and omissions, bear with me.

Guess you like

Origin www.cnblogs.com/miliam-12/p/11689751.html