Close

Java 8 Functional Interfaces - BinaryOperator.andThen() Examples

Java 8 Functional Interfaces Java Java API 


Interface:

java.util.function.BinaryOperator<T>

java.util.function.BiFunctionBiFunctionjava.util.function.BinaryOperatorBinaryOperatorLogicBig

Method:

default <V> BiFunction<T,T,V> andThen(Function<? super R,? extends V> after)

Returns a composed function that first applies this function to its input, and then applies the after function to the result.

In other words the 'after' function maps the return value of this BinaryOperator<T> from type T to type V.


Examples


package com.logicbig.example.binaryoperator;

import java.util.function.BiFunction;
import java.util.function.BinaryOperator;

public class AndThenExample {

public static void main(String... args) {
BinaryOperator<Integer> integerAdder = Math::addExact;
BiFunction<Integer, Integer, Double> squareRootOfSum = integerAdder.andThen(Math::sqrt);
Double d = squareRootOfSum.apply(7, 9);
System.out.println(d);
}
}

Output

4.0




See Also