Spark基礎-Scala提取器

Xlucas發表於2017-09-03

核心
1、scala提取器unapply

package com.xlucas

/**
  * Created by xlucas on 2017/9/3 0003.
  */

case class Person1(name:String,age:Int)
object ExtractorOop{
  def main(args: Array[String]): Unit = {
    val person=Person1.apply("spark",6)//呼叫apply工廠構造方法構造出類物件例項
    val Person1(name,age)=person//呼叫UNapply方法將物件person中的name和age提取出來並賦值給Person1
    println(name+":"+age )

    person match {
      case Person1(name,age)=>println("unapply"+name+":"+age)
    }
  }
}

相關文章