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