模式匹配高级实战:嵌套的Case class之Scala学习笔记-21

package com.leegh.pattern_match

/**
* @author Guohui Li
*/

abstract class Item
case class Book(description: String,price: Double) extends Item
case class Bundle(description: String,price: Double,items:Item*) extends Item
object Pattern_Match_Case_Class_Nested {
def main(args: Array[String]): Unit = {
def caseclass_nested(person:Item)= person match{
case Bundle(_,_,Book(descr,_),_*) => println("The first description is :"+descr)
case _ => println("Oops!")
}
caseclass_nested(Bundle("1111 Special's",30.0,Book("Scala for the Spark Developer",59.95),
Bundle("Hadoop",40.0,Book("Hive",79.95),Book("HBase",32.95))))
caseclass_nested(Bundle("1212 Special's",35.0,Book("Spark for the Impatient",59.95)))
}
}

 

附:

本博客说明:

1.整理思路,提高自己。

2.受教于王家林老师,​有所收获,故推荐。

3.博客注重实践,多余的文字就不多说了,都是做技术的。

4.信息来源于 DT大数据梦工厂微信公众账号:DT_Spark。​

DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。

Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载:

百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2

posted on 2015-08-14 07:33  李格非  阅读(349)  评论(0编辑  收藏  举报