为什么密封类型绑定的类型参数看起来not会引发穷举性警告
sealed trait A
case class B() extends A
case class C(i: Option[Int]) extends A
def f[T <: A](a: T) =
a match {
case B() =>
case C(None) =>
}
f(C(Some(42))) // throws MatchError
没有类型参数的想法
def f(a: A) =
a match {
case B() =>
case C(None) =>
}
发出警告
warning: match may not be exhaustive.
It would fail on the following input: C(Some(_))
a match {
^
模式匹配
def f[T <: A](a: T) =
a match {
case B() =>
case C(None) =>
}