Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

20.9 Enumerationsย >ย 20.9 Enumerations - Pg. 431

S ECTION 20.9 ยท Enumerations This object definition provides three values: Color.Red , Color.Green , and Color.Blue . You could also import everything in Color with: import Color._ and then just use Red , Green , and Blue . But what is the type of these values? Enumeration defines an inner class named Value , and the same-named pa- rameterless Value method returns a fresh instance of that class. This means that a value such as Color.Red is of type Color.Value . Color.Value is the type of all enumeration values defined in object Color . It's a path-dependent type, with Color being the path and Value being the dependent type. What's significant about this is that it is a completely new type, different from all other types. In particular, if you would define another enumeration, such as: object Direction extends Enumeration { val North, East, South, West = Value } then Direction.Value would be different from Color.Value because the path parts of the two types differ. Scala's Enumeration class also offers many other features found in the