1 package cn.itsource_01lambda_function; 2 3 import java.util.function.Function; 4 5 /** 6 * lambda对实例方法的使用: 7 * Function接口 8 * 传入一个参数,根据具体的业务逻辑处理后,返回一个结果值 9 * //继续优化 10 Function<String, Boolean> f2 = t -> t.endsWith(".avi"); 11 Boolean b = f2.apply(name);//判断name是否是.avi结尾 12 //最后优化 13 Function<String, Boolean> f3 =name::endsWith; 14 Boolean b1 = f3.apply(".avi");//判断name是否是.avi结尾 15 * @author Administrator 16 * 17 */ 18 public class LambdaStaticTest { 19 20 public static void main(String[] args) { 21 String name = "再见雨梨.avi"; 22 23 // Function<String, Boolean> f = new Function<String, Boolean>() { 24 // 25 // @Override 26 // public Boolean apply(String t) { 27 // if(t.endsWith(".avi")){ 28 // return true; 29 // } 30 // return false; 31 // } 32 // }; 33 // Boolean apply = f.apply(name); 34 // System.out.println(apply); 35 //第一步优化 36 Function<String, Boolean> f1 = t -> { 37 if(t.endsWith(".avi")){ 38 return true; 39 } 40 return false; 41 42 }; 43 //继续优化 44 Function<String, Boolean> f2 = t -> t.endsWith(".avi"); 45 Boolean b = f2.apply(name);//判断name是否是.avi结尾 46 //最后优化 47 Function<String, Boolean> f3 =name::endsWith; 48 Boolean b1 = f3.apply(".avi");//判断name是否是.avi结尾 49 50 51 52 53 54 55 } 56 57 }
标签:11,Function,26,01,name,endsWith,Boolean,avi,apply From: https://www.cnblogs.com/puwei520/p/16927321.html