码迷,mamicode.com
首页 > 其他好文 > 详细

PatternMatching

时间:2016-04-19 00:31:12      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

object PatternMatching {
  def main(args: Array[String]): Unit = {
    val x = List(1, 2, 3, 4, 5) match {
      case ::(x, ::(2, ::(4, _)))        => x
      case Nil                           => 42
      case ::(x, ::(y, ::(3, ::(4, _)))) => x + y
      case ::(h, t)                      => h + t.sum
      case _                             => 101
    }
    println(x)
  }
}

 

3

 

PatternMatching

标签:

原文地址:http://www.cnblogs.com/JonkeyGuan/p/5406366.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!