What is a recursion base case, and why can recursive code cause StackOverflowError in production?
Short answer
The base case is recursion's stopping condition; every call must move closer to it. With no base case, or recursion that goes too deep, the JVM throws StackOverflowError.
3 points to say:
- Each call takes one frame on the stack.
- Java does not optimize tail calls.
- For large data, switch to a loop.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.