Skip to content

Instantly share code, notes, and snippets.

@squito
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squito/9259375 to your computer and use it in GitHub Desktop.
Save squito/9259375 to your computer and use it in GitHub Desktop.
scala enums inferior

Every so often, somebody asks why I still use Java enums instead of scala "enums". Too avoid having to search for the links every time:

  1. what is a scala "enum"? scala itself can't decide. This stack overflow question mostly summarizes the alternatives, and how come each one is incomplete. http://stackoverflow.com/questions/1321745/scala-doesnt-have-enums-what-to-use-instead-of-an-enum

if you really take some time to understand those answers, you'll see people have invested quite a bit of effort to try and mimic the behavior of java enums, and its still lacking. If you want to see even more craziness:

http://stackoverflow.com/questions/20089920/custom-scala-enum-most-elegant-version-searched

  1. On top of that, the syntax for all scala versions is weird ... I need to type more, to get less

  2. You're still missing EnumMap and EnumSet, some of the most powerful parts of java enums! of course java enums have a lot more too, but those are big.

  3. b/c of the limitations of scala enums, Sumac only supports java enums. perhaps with some work it could support Enumerations, but I think it would take some macro magic for it to support sealed traits w/ case objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment