Skip to content

Instantly share code, notes, and snippets.

@d6y
Created November 1, 2014 17:23
Show Gist options
  • Select an option

  • Save d6y/8e770f7545e15c9aea13 to your computer and use it in GitHub Desktop.

Select an option

Save d6y/8e770f7545e15c9aea13 to your computer and use it in GitHub Desktop.
Enumerations & Method Overload
scala> :paste
// Entering paste mode (ctrl-D to finish)
object Colours extends Enumeration {
val Red, Amber, Green = Value
}
object WeekDays extends Enumeration {
val Mon,Tue,Wed,Thu,Fri = Value
}
object Functions {
def f(x: Colours.Value) = "That's a colour"
def f(x: WeekDays.Value) = "That's a weekday"
}
// Exiting paste mode, now interpreting.
<console>:19: error: double definition:
def f(x: Colours.Value): String at line 18 and
def f(x: WeekDays.Value): String at line 19
have same type after erasure: (x: Enumeration#Value)String
def f(x: WeekDays.Value) = "That's a weekday"
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment