this seems to not be possible with dart? i.e. to have a class method recurse and eventually return an object? when i run a recursive method it invariably returns null IF it has recursed at least once…
example:
// 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;
}
}
in some other class or in main:
rock g = rock_thower.throw_rock();
// if rock thrower has had to recurse
// g will be null...
I am VERY new to dart and am not sure why that happens. Any ideas? Is this sane?
If not: what am I doing wrong?
It would need to be
return this.throw_rock().Which is to say, you want to return either your
to_throwvariable, or the result of the recursive call.