Why Some(null) isn't considered None?

前端 未结 6 1872
感动是毒
感动是毒 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:12

    You should use Option(null) to reach the desired effect and return None.

    Some(null) just creates a new Option with a defined value (hence Some) which is actually null, and there are few valid reasons to ever create one like this in real code.

提交回复
热议问题