()与{}在foreach情况下

时间:2018-07-03 20:15:39

标签: scala foreach case

在下面的Scala代码中,使用foreach遍历元组列表,

val t1 = List((1,"A"), (2, "B"))

t1.foreach{
  case(id, name) => println(id, name)
}

t1.foreach(x => println(x))

t1.foreach(case(id, name) => println(id, name))

error: illegal start of simple expression
           t1.foreach(case(id, name) => println(id, name))
                      ^

为什么{}有效,first()有效,而last()返回错误?

0 个答案:

没有答案