public void test1(){Runnable runnable = new Runnable() {@Overridepublic void run() {System.out.println("谎言和誓言的区别是什么");}};runnable.run();System.out.println("**************************");Runnable runnable1 = () -> System.out.println("听的人信了,说的人信了");runnable1.run();}
public void test2(){Consumer<String> consumer = new Consumer<String>() {@Overridepublic void accept(String s) {System.out.println(s);}};consumer.accept("当你凝望深渊时");System.out.println("*********************************");Consumer<String> consumer1 = (String s) -> System.out.println(s);consumer1.accept("深渊也凝望着你");}
public void test3(){Consumer<String> consumer = (s) -> System.out.println(s);consumer.accept("在自己的身上克服这个时代");}
public void test4(){Consumer<String> consumer = s -> System.out.println(s);consumer.accept("每一个不曾起舞的日子,都是对生命的辜负");}
public void test5(){Comparator<Integer> comparator = new Comparator<Integer>() {@Overridepublic int compare(Integer o1, Integer o2) {System.out.println(o1);System.out.println(o2);return o1pareTo(o2);}};System.out.println("************************");Comparator<Integer> comparator1 = (o1,o2) -> {System.out.println(o1);System.out.println(o2);return o1pareTo(o2);};}
public void test6(){Comparator<Integer> c1 = (o1, o2) -> o1pareTo(o2);System.out.println(c1pare(13,12));}
方法引用:使用情况:当传递给Lambda体的操作,已经有实现的方法了,可以使用方法引用!
public void test1(){Consumer<String> co1 = str -> System.out.println(str);co1.accept("咸鱼");System.out.println("**************************");Consumer<String> co2 = System.out :: println;co2.accept("xianyu");}
public void test2(){Employee employee = new Employee(999,"小明",18,666);Supplier<String> su1 = () -> Name();System.out.());System.out.println("************************");Supplier<String> su2 = employee ::getName;System.out.());}
public void test3(){Comparator<Integer> com1 = (t1,t2) -> Integerpare(t1,t2);System.out.println(com1pare(22,21));System.out.println("************************");Comparator<Integer> com2 = Integer::compare;System.out.println(com2pare(22,21));}
public void test4(){Function<Double,Long> fun = new Function<Double, Long>() {@Overridepublic Long apply(Double aDouble) {und(aDouble);}};System.out.println(fun.apply(9.9));System.out.println("*******************");Function<Double,Long> function = Math::round;System.out.println(function.apply(9.9));}
public void test5(){Comparator<String> com = (c1,c2) -> c1pareTo(c2);System.out.println(compare("adc","acd"));System.out.println("******************");Comparator<String> com1 = String::compareTo;System.out.println(com1pare("abd","adm"));}
public void test6(){BiPredicate<String,String> biPredicate = (b1,b2) -> b1.equals(b2);System.out.st("abc","abc"));System.out.println("**********************");BiPredicate<String,String> bi = biPredicate::test;System.out.st("abc","abc"));}
public void test7(){Employee employee = new Employee(888, "小李", 18, 880);Function<Employee,String> stringFunction = e -> e.getName();System.out.println(stringFunction.apply(employee));System.out.println("***********************");Function<Employee,String> function = Employee::getName;System.out.println(function.apply(employee));}
public void test1(){Supplier<Employee> sup = () -> new Employee();System.out.());System.out.println("*********************");Supplier<Employee> sup1 = Employee::new;System.out.());}
public void test2(){Function<Integer,String[]> function = Length -> new String[Length];String[] apply = function.apply(6);System.out.String(apply));System.out.println("*********************");Function<Integer,String[]> function1 = String[]::new;String[] apply1 = function1.apply(6);System.out.println(apply1);}
本文发布于:2024-02-01 01:05:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170672070732712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |