Skip to content

Instantly share code, notes, and snippets.

@shatestest
Created October 26, 2018 12:02
Show Gist options
  • Save shatestest/1e2a1eac4de10199a1fbc693a7d48c09 to your computer and use it in GitHub Desktop.
Save shatestest/1e2a1eac4de10199a1fbc693a7d48c09 to your computer and use it in GitHub Desktop.
trait Processor {
def process()=println("default process")
}
case class ProcessorOne() extends Processor
case class ProcessorTwo() extends Processor {
override def process=println("process 2")
}
case class ProcessorThree() extends Processor {
override def process=println("process 3")
}
object DemoProc {
def main( args : Array[String]):Unit ={
val myFuncs2 : Map[String, () => Unit]=
Map(
"string1" -> (() => ProcessorOne().process),
"string2" -> (() => ProcessorTwo().process),
"string3" -> (() => ProcessorThree().process)
)
myFuncs2.values.foreach(v => v());
val myFuncs : Map[String, () => Unit]=
Map(
"string1" -> (() => (new ProcessorOne()).process),
"string2" -> (() => (new ProcessorTwo()).process),
"string3" -> (() => (new ProcessorThree()).process)
)
myFuncs.values.foreach(v => v());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment