尽管它可以进行尾递归优化,但这是否有意义呢?
def areStreamsEqual(stream1: InputStream, stream2: InputStream): Boolean =
{
val one = stream1.read()
val two = stream2.read()
if(one != two)
false
else if(one == -1 && two == -1)
true
else
areStreamsEqual(stream1, stream2)
}
有没有办法强制Scala编译器在这里进行尾调用优化?