I'm still learning functional interfaces. I'd like to know why I'm able to chain a
UnaryOperator
Function
IntUnaryOperator
UnaryOperator <String> twoOfMe = s -> s + s;
Function <String, Integer> convertMe = s -> Integer.parseInt (s);
UnaryOperator <Integer> twiceMe = n -> 2*n;
IntUnaryOperator doubleMe = n -> 2*n;
int a = twoOfMe.andThen(convertMe).andThen(twiceMe).apply ("2");
int b = twoOfMe.andThen(convertMe).andThen(doubleMe).apply ("2");
int a
twiceMe
int b
doubleMe
andThen(Function<? super R, ? extends V> after)
expects a Function
argument. UnaryOperator<Integer>
is a sub-interface of Function<Integer,Integer>
, which matches. IntUnaryOperator
has no relation to the Function
interface, so doubleMe
cannot be passed to andThen
.