以下是引发编译错误的最小代码:“不在尾部位置的递归调用”。但是,我使用的是@inline
,而递归调用是处于尾部位置。我使用这个@inline
的原因是我有两次重复的原始reccall
的代码。无法优化方法
import scala.annotation._
object Test {
@tailrec private def test(i: Int): Int = {
@inline def reccall(i: Int): Int = test(i-1)
i match {
case 0 => 0
case i => reccall(i)
}
}
}
我看了答案Recursive call not in tail position@tailrec why does this method not compile with 'contains a recursive call not in tail position'?,但他们并不适用于我的情况。使用Scala的2.12
可能的重复https://stackoverflow.com/questions/25582515/make-method-actually-inline –