Tail call optimization is not a mere optimization. A jvm cannot provide it and still provide conforming exception stack traces, for example.
As far as closures: you're missing out :)
Tail call optimization is not a mere optimization. A jvm cannot provide it and still provide conforming exception stack traces, for example.
As far as closures: you're missing out :)
It just won't run (for very long). :)
If you find yourself wanting to pass in Collection<Firetruck> to a method that only accepts Collection<IVehicle>, this usually means that the method isn't correctly typed. The rule of thumb for using 'super' and 'extends' is "Producer extends, Consumer super" or PECS. By applying this, the typing problem should go away, as your method is now accepting Collection<T extends IVehicle> and possibly returning Collection<? super T>, so you can both pass in your Collection<Firetruck> and reassign to a different variable of type Collection<Firetruck>. :)
(I think Josh Bloch wrote up a decent blog post about the PECS principle a couple of years ago. It might be worth reading for more information.)
int A() { return 1 + B(); }
int B() { return 1 + A(); }
(with necessary ending conditions)
Note that your example was not of tail calls, however. (Tail call would be: return A(...); that is, a tail call is one whose result is immediately returned.)
And, woops...