[英]What is the purpose of lower bounded wildcard in Function.class?
In Function.class from Java8, we have: 在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));
}
Compose accepts: 撰写接受:
Function<? super V, ? extends T> before
Rather than: 而不是:
Function<V, ? extends T> before
Is there any plausible situation in which the fact that "V" is lower bounded matters? 是否存在“ V”是下界这一事实的合理情况?
The ? super
? super
? super
allows the returned Function
's input type ( V
) to be different from the arguments input type. ? super
允许返回的Function
的输入类型( V
)与参数输入类型不同。
For example, this compiles with the ? super
例如,用? super
编译? super
? super
version but not the alternate one. ? 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.