Package Com.dtspark.scala.basics
/**
* Implicits implicit conversion real-combat
*/
Class Man (Val name:string)
/*object man{
Implicit def man2superman (Man:man) =new Superman (Man.name)
}*/
Object implicits{
Implicit def man2superman (Man:man) =new Superman (Man.name)
}
Class Superman (Val name:string) {
def makemiracles=println (this.name+ "Wow,wow,wow ...")
}
Object Helloimplicits {
def main (args:array[string]): Unit = {
Import Implicits Package
Import Com.dtspark.scala.basics.implicits._
Instantiating associated classes
Val man=new man ("Scala")
Execution method
Man. Makemiracles
}
Implicit val content= "Hello"
Talk ("Scala") ("Spark")
Def talk (name:string) (implicit content:string) =println (name + ":" +content)
}
Operation Result:
Scala:spark
Scalawow,wow,wow ...
This article from "8381513" blog, declined reprint!
Mushroom Cloud Action prequel 16th: Scala implicits programming thorough combat and spark source appreciation