0
点赞
收藏
分享

微信扫一扫

chatgpt赋能python:Python如何取非

东言肆语 2023-06-06 阅读 61
package com.jack.modules.base.controller;

import java.util.function.Function;

/**
 * @author 苏煦
 * @date 2023/5/27 16:13
 * @desc
 */
public class Main {
    public static void main(String[] args) {
        // 使用 Function 函数式接口进行函数组合
        Function<Integer, Integer> addOne = num -> num + 1;
        Function<Integer, Integer> multiplyByTwo = num -> num * 2;

        /**
         * composedFunction 是通过将 addOne 函数和 multiplyByTwo 函数进行组合而得到的。
         * addOne.andThen(multiplyByTwo) 表示先应用 addOne 函数,然后将其结果作为参数应用于 multiplyByTwo 函数
         */
        Function<Integer, Integer> composedFunction = addOne.andThen(multiplyByTwo);

        // 执行函数组合
        int result = composedFunction.apply(3);
        System.out.println(result); // 输出: 8

    }
}
举报

相关推荐

0 条评论