为什么Some(null)不被视为None? [英] Why Some(null) isn't considered None?
本文介绍了为什么Some(null)不被视为None?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇:
scala> Some(null) == None
res10: Boolean = false
为什么Some(null)
不能转换为None
?
推荐答案
您应使用Option(null)
达到所需的效果并返回None
.
You should use Option(null)
to reach the desired effect and return None
.
Some(null)
只是使用定义的值(因此为null
)创建一个新的Option
,而该值实际上是null
,并且没有充分的理由在真实代码中创建这样的一个.
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.
这篇关于为什么Some(null)不被视为None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文