标签:
Testing
case class Person(name: String, age:Int) class DTCoder(val name: String, val salary: Int) object DTCoder{ def apply(name: String, salary:Int):DTCoder = { println("DTCoder apply method invoked!!!") new DTCoder(name, salary) } def unapply(information: DTCoder) = { Some((information.name,information.salary)) } } object HelloExtractor { def main(args: Array[String]){ val p = Person.apply("Spark",6) val Person(name,age) = p println(name + " : " + age) p match { case Person(name,age) => println("Wow..." + name + ":" + age) } val dtcoder = DTCoder("Spark",1000000) val DTCoder(dtname,salary) = dtcoder dtcoder match { case DTCoder(dtname,salary) => println("Wow..." + dtname + ":" + salary) } } }
标签:
原文地址:http://www.cnblogs.com/jcchoiling/p/5758908.html