Scalaenum不像 Java 那样具有类型安全的 s。给定一组相关的常量,Scala 中表示这些常量的最佳方式是什么?
enum
http://www.scala- lang.org/docu/files/api/scala/Enumeration.html
示例使用
object Main extends App { object WeekDay extends Enumeration { type WeekDay = Value val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } import WeekDay._ def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun) WeekDay.values filter isWorkingDay foreach println }