Created
December 24, 2012 17:41
-
-
Save anonymous/4370153 to your computer and use it in GitHub Desktop.
Initialization in value classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
› 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