【发布时间】:2022-01-22 05:29:43
【问题描述】:
我有以下代码:
Function<String,Integer> f1=s->Integer.valueOf(s)+1;
Function<String,Integer> f2=s->Integer.valueOf(s)*2;
Function<String,Integer> f3=f1.compose(f2);
这是我得到的错误:
method compose in interface Function<T,R> cannot be applied to given types;
这段代码有什么问题?
然后我查看了文档中的compose():
default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
Objects.requireNonNull(before);
return (V v) -> apply(before.apply(v));
}
我无法完全理解它。谁能给我解释一下可以组合的函数的参数之间的关系?
【问题讨论】: