So vermeiden Sie StackOverflowError für eine rekursive Funktion
Ich schreibe eine Funktion, die sich bis zu 5000 Mal selbst aufruft. Natürlich bekomme ich eineStackOverflowError
. Gibt es eine Möglichkeit, diesen Code auf relativ einfache Weise umzuschreiben ?:
<code>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 } </code>
Was ist übrigens die Einschränkung, wie tief wir die Funktionen aufrufen dürfen?