【发布时间】:2018-03-11 03:37:07
【问题描述】:
我目前正在尝试让高阶函数工作,但它一直告诉我 f 可能尚未定义。我的理解是它应该被定义为必须给出它才能运行 IntApply 方法。任何建议将不胜感激。
package iterators;
import java.util.Iterator;
public class IntApply implements Iterator {
// The function that will be applied to each input element to make an output element
private final IntApplyFunction f;
// The Iterator that this Apply object will get its input from
private final Iterator<Integer> input;
public IntApply(IntApplyFunction f, Iterator<Integer> input) {
while(input.hasNext()){
f.apply(input.next());
}
}
@Override
public boolean hasNext() {
return input.hasNext();
}
@Override
public Integer next() {
return input.next();
}
}
【问题讨论】:
-
发布您的代码而不是图片
-
只是提示,如果您将代码发布为图片,这里的人会将您钉死在十字架上。人们希望能够复制和粘贴代码以自己进行测试。
-
我很抱歉,进行了更改
标签: java higher-order-functions