You would need to create a singleton companion object MeasureType
and write withValue
method by hand using pattern matching on the argument.
object MeasureType {
def withValue(val : String) : MeasureType = val match {
case "Hour" => Hour
case "Day" => Day
case "Week" => Week
case "Month" => Month
case _ => throw new IllegalArgumentException("unrecognized name: " + val);
}
}