List(1,2) match {
case List(1,_) => println("1 in postion 1")
case _ => println("default")
}
编译/工作正常。 所以做斯卡拉列表匹配
List(1) match ...
List(3,4,5) match ...
但不
List() match ...
这将导致以下错误
found : Int(1)
required : Nothing
case List(1,_) => println("1 in postion 1")
为什么列表()尝试匹配列表(1,_)?
这是什么意思是'List [Int]'可以强制为'List [Nothing]',但其他方式是不可能的。 – missingfaktor 2010-08-27 15:53:38