- 课程名称:JAVA 函数式编程-慕课网 (imooc.com)
- 章节名称:
- 第1章:课程介绍
- 1-3:函数式编程的特点
- 第1章:课程介绍
- 讲师姓名:接灰的电子产品
- 时间:2022-11-15 21:38
课程内容
- 纯函数
- 函数的执行没有副作用
- 返回值仅依赖于输入参数
- 高阶函数
- 函数的参数可以是一个或多个函数
- 函数的返回值也可以是一个函数
- 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);
课程收获
这些内容应该都会,但老师一讲发现又都忘记啦,太不应该
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦