继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【金秋打卡】第23天-Java函数式编程-特点

taoy
关注TA
已关注
手记 94
粉丝 9
获赞 1

课程内容

  • 纯函数
    • 函数的执行没有副作用
    • 返回值仅依赖于输入参数
  • 高阶函数
    • 函数的参数可以是一个或多个函数
    • 函数的返回值也可以是一个函数
  • Lambda表达式
    • 箭头左边是参数列表,右边是函数体
    • 方法引用class::method
  • Java函数式接口
    • 有且仅有一个未实现的非静态方法的接口叫做“函数式接口”
  • 内建的函数式接口
    • Function <Long, Long> = v -> v + 3;
    • Predicate<Object> predicate = v -> v == null;
    • UnaryOperator<User> uo = user -> {user.setName("a"); return user;}
    • BinaryOperator<Long> bo = (a, b) -> a + b;
    • Supplier<Integer> supplier = () -> (int)Math.random(1000D);
    • Consumer<Integer> consumer = v -> log.debug({}, v);
  • 函数的组合
    • and / or
      • Predicate<String> startsWithA = t -> t.startWith("A");
      • Predicate<String> endsWithX = t -> t.endWith("x");
      • Predicate<String> swAandEndx = startWithA.and(endsWithX)
    • compose / andthen
      • Function<Integer, Integer> squareOp = v -> value * value;
      • Function<Integer, Integer> = doubleOp = v -> 2 * value;
      • Function<Integer, Integer> doubleThenSquare = squareOp.compose(doubleOp);

课程收获

这些内容应该都会,但老师一讲发现又都忘记啦,太不应该
函数式编程特点

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP