// functional/TransformFunction.java // (c)2017 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://OnJava8.com for more book information. import java.util.function.*; class I { @Override public String toString() { return "I"; } } class O { @Override public String toString() { return "O"; } } public class TransformFunction { static Function transform(Function in) { return in.andThen(o -> { System.out.println(o); return o; }); } public static void main(String[] args) { Function f2 = transform(i -> { System.out.println(i); return new O(); }); O o = f2.apply(new I()); } } /* Output: I O */