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