Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2012 17:41
Show Gist options
  • Save anonymous/4370153 to your computer and use it in GitHub Desktop.
Save anonymous/4370153 to your computer and use it in GitHub Desktop.
Initialization in value classes
› cat valueClasses.scala
class Age(val v: Short) extends AnyVal {
require(v >= 0 && v < 200, "Must be between 0 and 200")
def isInfant = v < 2
def isToddler = v >= 2 && v <= 4
def isSenior = v >= 50
}
in ~/Downloads/
› ./scala-2.10.0-RC5/bin/scalac valueClasses.scala
valueClasses.scala:2: error: this statement is not allowed in value class
require(v >= 0 && v < 200, "Must be between 0 and 200")
^
one error found
in ~/Downloads/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment