java_函数式编程写法

 1 package cn.aikang.Test;
 2 
 3 import org.junit.Test;
 4 
 5 import java.util.Scanner;
 6 import java.util.function.Supplier;
 7 
 8 public class Test01 {
 9     //定义一个方法,方法的参数是一个接口
10     //使用该方法生产一个字符串
11     public static  String show(Supplier<String> sup){
12         return sup.get();
13     }
14 
15     public static void main(String[] args) {
16         //调用生产字符串的方法,使用匿名函数重写他的方法
17         /*String a = show(()->{
18             return  "喂!你好";
19         });*/
20         //简化:
21         String a = show(()->"喂!你好");
22         System.out.println(a);
23     }
24 }

猜你喜欢

转载自www.cnblogs.com/aikang525/p/11404850.html