这似乎是不可能的飞镖?即让一个类方法递归并最终返回一个对象?当我运行递归方法时,如果它至少递归一次,它总是返回 null ......
例子:
// some class method
rock throw_rock() {
// look at its own collection of rocks
// get a rock and do a test on it
rock to_throw = this.rocks[53]; // lets assume its in a map at key 53...
if (to_throw.been_thrown == 1) {
// ok, dont throw this one, instead recurse and find another
this.throw_rock();
} else {
return to_throw;
}
}
在其他一些课程或主要课程中:
rock g = rock_thower.throw_rock();
// if rock thrower has had to recurse
// g will be null...
我对飞镖很陌生,不知道为什么会这样。有任何想法吗?这是理智的吗?
如果不是:我做错了什么?