f1.andThen(f2)は、f1,f2
f1.compose(f2)は、f2,f1
下記の例
fc1 integer→string, string→integer
fc2 string→integer, integer→string
public class Outer {
public static void main(String[] args) {
Function<Integer, String> f1 = x -> String.valueOf(x + 2);
Function<String, Integer> f2 = x -> Integer.valueOf(x) * 2;
Function<Integer, Integer> fc1 = f1.andThen(f2);
System.out.println(fc1.apply(5));
System.out.println(f1.andThen(f2).apply(5));
Function<String, String> fc2 = f1.compose(f2);
System.out.println(fc2.apply("5"));
System.out.println(f1.compose(f2).apply("5"));
}
14
14
12
12