Mushroom Cloud Action prequel 16th: Scala implicits programming thorough combat and spark source appreciation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.