有人可以给我一个提示,为什么我会收到此错误?
object TestObject {
def main (args : Array[String]) : Unit = {
val list = List(1, 1, 2, 3, 5, 8)
val lastElem = findLast(list) <-------------------------- Here is a problem
}
def findLast[T](ls : List[T]) : T = {
if(ls.isEmpty) throw new Exception("List is empty")
else if(ls.tail.isEmpty) ls.head
else findLast(ls.tail)
}
}
错误消息是:
type mismatch; found : List[Int] required: List[?]