当我们有一个类型为Amount的对象时候,可以用模式匹配来匹配他的类型,并将属性值绑定到变量(即:把样例类对象的属性值提取到某个变量,该功能有用)
object MatchList {
def main(args: Array[String]): Unit = {
for(list <- Array(List(0),List(1,0),List(0,0,0),List(1,0,0))){
val result = list match {
case 0 :: Nil => "0" //
case x :: y :: Nil => x + "" + y //
case 0 :: tail => "0 ...."
}
// 1.0
// 2.1 0
// 3.0....
// 4.something else
println(result)
}
}
}
//类型(对象)=序列化(serializable)==>字符串形式(1你可以保存到文件中[freeze],2.使用反序列化
3.网络传输