看来Nil的类型并不多变。 我如何纠正这一职能:
scala> def last[A](a:List[A]) : A =
| a match {
| case _ :: tail => last(tail)
| case Nil => Nil[A]
| }
<console>:8: error: object Nil does not take type parameters.
case Nil => Nil[A]
最新资料:
scala> def last[A](a : List[A] ) : Option[A] =
| a match {
| case head :: Nil => Some(head)
| case _ :: tail => last(tail)
| case Nil => None
| }