1
在斯卡拉的type erasure
閱讀這個優秀question/answer後,我試過這段代碼。 Scala編譯器沒有輸出type erasure
警告。爲什麼沒有類型擦除警告
scala> val x: List[Int] = List(1,2,3)
x: List[Int] = List(1, 2, 3)
scala> x match {
| case List(x: Int) => println("a")
| case _ => println("false")
| }
false
沒有上面的代碼輸出相同的警告,這段代碼爲什麼:
scala> List(1,2,3) match {
| case l: List[String] => println("list of strings")
| case _ => println("ok")
| }
<console>:9: warning: fruitless type test: a value of type List[Int] cannot
also be a List[String] (but still might match its erasure)
case l: List[String] => println("list of strings")
^
list of strings