I have a question about tail calls optimization, I need to know how this java code behaves:
private void doSomething(int v) {
inf f = someCalculation(v);
if (f < 0) doSomething(v/2);
else doSomething(v*2);
}
This code is a nonsense example but my question is, in such a case:
- The first doSomething() call would be optimized?
- The second doSomething() call would be optimized?
- The if/else block affects in any way the optimization?
Thanks
EDIT:
Please provide an example on how you would do this if the language was not Java but something else that has TCO