为什么 Some(null) 不被认为是 None? [英] Why Some(null) isn't considered None?

查看:23
本文介绍了为什么 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) 只是创建一个新的 Option 和一个定义的值(因此 Some),它实际上是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆