[英]What is the purpose of lower bounded wildcard in Function.class?
在Java8的Function.class中,我们具有:
default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
Objects.requireNonNull(before);
return (V v) -> apply(before.apply(v));
}
撰写接受:
Function<? super V, ? extends T> before
而不是:
Function<V, ? extends T> before
是否存在“ V”是下界这一事实的合理情况?
? super
? super
允许返回的Function
的输入类型( V
)与参数输入类型不同。
例如,用? super
编译? super
? super
版本,但不是备用版本。
Function<Object, String> before = Object::toString;
Function<String, Integer> after = Integer::parseInt;
Function<Integer, Integer> composed = after.compose(before);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.