3 ms·
Not sure if this is accurate. You can enforce @tailrec if you want, but I believe it will try to in any case, even if it is not annotated.
by freekh 6y ago
Not sure if this is accurate. You can enforce @tailrec if you want, but I believe it will try to in any case, even if it is not annotated.
- yashap 6y agoThis is correct. @tailrec will simply cause a compile failure if the compiler DOESN’T optimize the function, but the compiler does still optimize tail recursion without the annotation. It’s a weird but helpful annotation. For example, Scala won’t optimize methods that can be overridden (non-final and public/protected), which is easy to forget. So the annotation is a nice check/confirmation that the compiler is doing what you expect.