I'm making a class that implements the java Math class and I'm overwriting the add method with a recursive one. I thought my method was pure tail recursive and wouldn't throw a stackoverflow, but I can't add 10000 and 10000 without throwing that.
public int add(int a, int b) {
if (b == 0)
return a;
return add(increase(a), decrease(b));
}
And the increase and decrease methods simply take in the number, add/subtract 1, and return the result. I don't think this should be creating any stack, as the method does not have to wait on any calculations from successive calls to finish. But I'm apparently wrong. Any ideas?