scala> val a = Array(1,2,3,4) a: Array[Int] = Array(1, 2, 3, 4)
有繁入简,
scala> a.map(x => x match { | case 0 => "zero" | case 1 => "one" | case 2 => "two" | case _ => "other" | }) res2: Array[String] = Array(one, two, other, other) scala> a.map(x => x match { case x => x }) res4: Array[Int] = Array(1, 2, 3, 4) scala> a.map(case x => x) <console>:1: error: illegal start of simple expression a.map(case x => x) ^ scala> a.map{case x => x} res3: Array[Int] = Array(1, 2, 3, 4) scala> a.map{x => x} res7: Array[Int] = Array(1, 2, 3, 4)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。