如何避免scala wart中没有包含任何内容的推断类型?

时间:2015-11-27 08:05:28

标签: scala scala-wartremover

使用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

1 个答案:

答案 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.
}