编程语言
首页 > 编程语言> > lamda函数式编程

lamda函数式编程

作者:互联网

lamda表达式

接受范围:

常用写法

匿名类简写

new Thread( () -> System.out.println("In Java8, Lambda expression rocks !!") ).start();
// 用法
(params) -> expression
(params) -> statement
(params) -> { statements }

forEach

// forEach
List features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Date and Time API");
features.forEach(n -> System.out.println(n));
 
// 使用Java 8的方法引用更方便,方法引用由::双冒号操作符标示,
features.forEach(System.out::println);

方法引用

构造方法引用  =》 
// Supplier<Student> s = () -> new Student();
Supplier<Student> s = Student::new;

实例方法的引用 =》 对象::实例方法
// set.forEach(t -> System.out.println(t));
set.forEach(System.out::println);

静态方法 =》 类名::静态方法 
// Stream<Double> stream = Stream.generate(() -> Math.random());
Stream<Double> stream = Stream.generate(Math::random);

类名::实例方法

标签:lamda,函数,Stream,编程,System,forEach,println,方法,out
来源: https://blog.csdn.net/m0_47437371/article/details/123201618