是不是所有類型的子類型?爲什麼地圖/過濾器...不適用於無數數組?
scala> val array = new Array(5)
array: Array[Nothing] = Array(null, null, null, null, null)
scala> array.map(_ => 42)
<console>:9: error: value map is not a member of Array[Nothing]
array.map(_ => 42)
^
scala> array.filter(_ != 42)
<console>:9: error: value filter is not a member of Array[Nothing]
array.filter(_ != 42)
^
這很奇怪,這是行不通的。
這是指定的功能還是錯誤?
'null'並不是真的'null',它更像是一個'throw new NullPointerException'。 'toString'有點誤導。 – soc 2011-04-30 18:23:28
@soc我意識到現在:編譯器實際上通過拋出「unboxes」null作爲Nothing。有趣的是,它並沒有在上面的'println(p.value)'上做。 – 2011-05-02 07:47:46