Scala Extractor __scala

Source: Internet
Author: User


Package Com.xing.listfile

/**
  * Created by Dengni on 2017/2/15.
  * * Case

class Datawarehouse (name:string, Age:int)
object Extrctmethod extends app{

  val dw = Datawarehouse (" Spark ", 100)//Invoke the Apply factory method constructs the instance object of the class
  Val datawarehouse (name, age) = DW//Call unapply method The name age in the DW instance  extracts the

  pri  NTLN (name + "  " + Age)

  //equivalent
  to DW match {case
    datawarehouse (name:string, Age:int) =>println ("1:::" +name + "  " + Age)
  }


//
  Val Dwcode (tablename, ages) = Dwcode ("Rmt_stage", 12)//The Apply method is used here  
 PRINTLN (tablename + "::" + Ages)



}
//More Example
class Dwcode (Val tablename:string, Val age:int) 
 object  dwcode{

  def apply (tablename:string, age:int): Dwcode = new Dwcode (  tablename, age)

  def Unapply (Arg:dwcode): option[(String, Int)] = {

    Some (arg.tablename,arg.age)

  }

}





Scala Extractor

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.