top | item 22953066

(no title)

freekh | 5 years 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.

discuss

order

yashap|5 years ago

This 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.