Created
October 26, 2018 12:02
-
-
Save shatestest/1e2a1eac4de10199a1fbc693a7d48c09 to your computer and use it in GitHub Desktop.
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
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