Why does map/filter … not work with an Array of Nothing?

后端 未结 3 595
忘掉有多难
忘掉有多难 2021-01-14 06:39

Isn\'t Nothing a subtype of all types?

scala> val array = new Array(5)
array: Array[Nothing] = Array(null, null, null, null, null)

scala> array.map(_          


        
3条回答
  •  暖寄归人
    2021-01-14 07:09

    When you see weird behavior involving Nothing, it's because the type inference algorithm thinks that it inserted Nothing itself, since it is introduced during type inference: if nothing is known about a type variable then it is bounded by Any and Nothing. It has long been on my list of things to do to see if I can introduce a new internal-only bottom type for that purpose so user-level Nothing and inference-level Nothing are not intermingled, but it's a pretty ambitious task. Still, I might now be hardcore enough to try it.

提交回复
热议问题