Why Some(null) isn't considered None?

前端 未结 6 1875
感动是毒
感动是毒 2020-12-15 02:38

I am curious:

scala> Some(null) == None
res10: Boolean = false

Why isn\'t Some(null) transformed to None?

6条回答
  •  星月不相逢
    2020-12-15 03:18

    As a simple thought experiment, consider two lists of Strings, one of length 5 and one of length 20.

    Because we're running on the JVM, it's possible to insert null as a valid element into one of these lists - so put that in the long list as element #10

    What, then, should the difference be in the values returned from the two following expressions?

    EDIT: Exchanged get for lift, I was thinking of maps...

    shortList.lift(10) //this element doesn't exist
    longList.lift(10)  //this element exists, and contains null
    

提交回复
热议问题