使用scala wart我得到:
def lastWithRecursion(input: Seq[Int]): Try[Int] = input match {
case head :: Nil => Success(head)
case _ :: tail => lastWithRecursion(tail)
case _ => Failure(new NoSuchElementException("No such element")) // how to avoid inferred type containing nothing.
}
如何避免inferred type containing nothing
?
答案 0 :(得分:5)
尝试将添加的通用添加到Failure
:
def lastWithRecursion(input: Seq[Int]): Try[Int] = input match {
case head :: Nil => Success(head)
case _ :: tail => lastWithRecursion(tail)
case _ => Failure[Int](new NoSuchElementException("No such element")) // how to avoid inferred type containing nothing.
}