class FibonacciSum
implements Generator<Integer>, Callable<Integer> {
private int count;
private final int n;
public FibonacciSum(int n) { this.n = n; }
public Integer next() { return fib(count++); }
private int fib(int n) {
if(n < 2) return 1;
return fib(n-2) + fib(n-1);
}
public Integer call() {
int sum = 0;
for(int i = 0; i < n; i++)
sum += next();//此处next()接收的是哪里的信息,可否详细讲解一下
return sum;
}
}
调用的上方定义的next()方法 会返回一个integer类型的值 赋值给sum
next() 是上面定义的一个方法,返回的是一个Integer