【JAVA】java8 function apply() compose() andThen()

 public static void main(String[] args) {
        Function plus = i -> i + 1;
        Function mult = i -> i * i;
        System.out.println("F1:" + plus.apply(1)); // 结果2
        System.out.println("F2:" + mult.compose(plus).apply(3)); // 等于mult.apply(plus.apply(2)), 结果16
        System.out.println("F3:" + mult.andThen(plus).apply(2)); // 等于plus.apply(mult.apply(2)), 结果5
    }

你可能感兴趣的:(【JAVA】java8 function apply() compose() andThen())