为什么在启用-unchecked
时,以下内容不会产生警告:
object Order {
sealed trait EntryOption
case object EmptyEntry extends EntryOption
trait Entry extends EntryOption
def isEmpty(a: EntryOption): Boolean = a match {
case EmptyEntry => true
// case _: Entry => false
}
}
在Scala 2.8.0的日子里,我似乎完全拥有same problem before,没有足够的答案。
修改
@Jed对我来说,仅对非抽象类Entry
发出警告是没有意义的。请考虑以下情况:
trait Order {
sealed trait EntryOption
case object EmptyEntry extends EntryOption
abstract sealed class Entry extends EntryOption
def isEmpty(a: EntryOption): Boolean = a match {
case EmptyEntry => true
// case _: Entry => false
}
}
trait OrderImpl extends Order {
final class EntryImpl extends Entry
}
出现警告的唯一方法是在Entry
中设置具体的课程Order
!
答案 0 :(得分:3)
它确实在主干上抱怨:
scala> object Order {
| sealed trait EntryOption
| case object EmptyEntry extends EntryOption
| trait Entry extends EntryOption
|
| def isEmpty( a: EntryOption ) : Boolean = a match {
| case EmptyEntry => true
| // case _: Entry => false
| }
| }
<console>:18: warning: match is not exhaustive!
missing combination Entry
def isEmpty( a: EntryOption ) : Boolean = a match {
^
defined module Order
答案 1 :(得分:2)
条目是一种特质,而不是案例类。