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