如何避免推断类型不包含 scala 疣?
how to avoid inferred type containing nothing with scala wart?
使用 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
?
尝试向 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.
}
使用 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
?
尝试向 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.
}