The signature of andThen is: (Function<? super R,? extends V> after)
I cannot understand why the input of the function is : ? super R
In my understanding, super is used when we are writing a value. But the function passed to andThen will read the value of first function.
For ex:
Function<Integer, Integer> f1 = x -> x * 2;
Function<Integer, Integer> f2 = x -> x * 3;
Integer myApplyThen = (input) -> {
Integer y1 = f1.apply(input);
Integer y2 = f2.apply(y1);
return y2;
}
As we can see in this logic that there is no need to write any value to the generic parameters passed to Function. Both f1.apply
and f2.apply
are just transforming their inputs i.e reading and returning.
So according to me, the type definition of andThen should have been: Function<? extends R,? extends V> after
But since this is not the case, what am I missing?