Created
January 20, 2011 00:57
-
-
Save bigtoast/787211 to your computer and use it in GitHub Desktop.
Notes on Scala Effective Enum patterns.
This file contains hidden or 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
sealed abstract class MyEnum | |
object MyEnum { | |
def apply(str :String) :MyEnum { // do str conversions } | |
object Val1 extends MyEnum | |
object Val2 extends MyEnum | |
} | |
we need the abstract class for matching the enum type. It can't be a trait because the compiler gets confused with the apply method in the object. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment