如何避免递归函数的 StackOverflowError
2022-09-03 05:21:54
我正在编写一个函数,它将调用自身大约5000次。当然,我得到一个.有没有办法以相当简单的方式重写这段代码?StackOverflowError
void checkBlocks(Block b, int amm) {
//Stuff that might issue a return call
Block blockDown = (Block) b.getRelative(BlockFace.DOWN);
if (condition)
checkBlocks(blockDown, amm);
Block blockUp = (Block) b.getRelative(BlockFace.UP);
if (condition)
checkBlocks(blockUp, amm);
//Same code 4 more times for each side
}
顺便说一句,我们可以调用函数的深度的限制是什么?