Skip to content

Instantly share code, notes, and snippets.

@lanceon
Created August 4, 2013 21:59
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 lanceon/6152125 to your computer and use it in GitHub Desktop.
Save lanceon/6152125 to your computer and use it in GitHub Desktop.
object VarargTest {
abstract class OptionBase
case class Width(s: String) extends OptionBase
case object HasSearch extends OptionBase
case class Title(s: String) extends OptionBase
implicit def strToOption(s:String) : OptionBase = Title(s)
def func(options: OptionBase*) {
options.foreach(o => println("option = [%s]".format(o)))
}
def main(args: Array[String]) {
func()
func("String promoted to Title()")
func(Title("My title"))
func(Title("Another title"), HasSearch)
func(Width("100px"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment