原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-29/

There I am,in the world more exciting!

by postbird

www.ptbird.cn


package com.ptbird.scala /** * Created by postbird on 2016/5/26. */ abstract class Item case class Book(description: String, price: Double) extends Item case class Bundle(description: String, price: Double, items: Item*) extends Item //items这个成员可以由若干个Item组成 object CaseClassObjectTest2 { def main(args: Array[String]): Unit = { def caseclass_nested(person: Item) = person match { // case Bundle(_, _, art@Book(_, _), rest@_*) => println(art.description + " " + art.price) case Bundle(_,_,Book(descr,_),_*)=>println("the first descr is : "+descr) case _ =>println("no!") } caseclass_nested(Bundle("1111, sprc's",69.23, Book("Scala for ther spark Developer",30.0), Bundle("Hadoop",40,Book("Hive",79.90),Book("HBase",32.33)) ) ) caseclass_nested(Bundle("1231 special's",32.00,Book("Spark for the impatent",39.09))) } }