The compiler can use this to perform exhaustiveness checking.
Another idiom related to sealed traits is to provide an alternative to enums.
object ScalaEnum extends App { sealed trait WeekDay case object Sun extends WeekDay case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case object Sat extends WeekDay def m(p: WeekDay) = println(p) m(Sat) // prints Sat }
No comments:
Post a Comment