繁体   English   中英

Function.class中的下界通配符的目的是什么?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM