Trying to understand the source code of java.util.Function
Have attempted to create my own version of this class, on comparing my version with source code, found one difference - unable to understand the reason behind usage of a generic type boundary.
myVersion
default <V> MyFunction<T, V> andThen(MyFunction<? super R, V> after) {
return t -> after.apply(apply(t));
}
javaSource
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t) -> after.apply(apply(t));
}
this is pretty much the same as java.util.Function
andThen
method except that instead of ? extends V
, V
has been used.
why is the type upper bound ? extends V
used in andThen
method - is there any scenario that will only work with ? extends V
and not with V
note: I understand the ? super R
part is required because without it, we will only be able to chain another function that has the input argument type exactly as R
Have the same doubt about the usage of ? super V
in compose
method also