scala – 将元组与null匹配
发布时间:2020-12-16 19:11:25 所属栏目:安全 来源:网络整理
导读:我不明白为什么以下情况不匹配. Null应该是Any的实例,但它不匹配.有人可以解释发生了什么吗? val x = (2,null)x match { case (i:Int,v:Any) = println("got tuple %s: %s".format(i,v)) case _ = println("catch all")}prints catch all 谢谢. 解决方法 这
我不明白为什么以下情况不匹配. Null应该是Any的实例,但它不匹配.有人可以解释发生了什么吗?
val x = (2,null) x match { case (i:Int,v:Any) => println("got tuple %s: %s".format(i,v)) case _ => println("catch all") } prints catch all 谢谢. 解决方法
这完全符合规定.
Type patterns consist of types,type variables,and wildcards. A type pattern T is of one of the following forms: * A reference to a class C,p.C,or T#C. This type pattern matches any non-null instance of the given class. 有趣的是,如此多的相关性归因于null是Any的成员.它是各种类型的成员,但AnyVal和Nothing. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Shell 查找与替换
- WebService:设置服务器提供SOAP1.2的服务
- vim插件安装 及 使用NERDTree分屏
- typescript – angular2 router.navigate里面的auth0回调
- 在Angular 2中调用环境(本机)特定的全局javascript函数
- AngularJS $Http CORS与Spring Rest&Security中的后端
- bash – 如何在AWS Cloud Formation启动时以不同的用户身份
- scala – 使用PostgreSQL和Slick自动增量字段
- 如何使用AngularJS过滤数组并使用过滤对象的属性作为ng-mod
- python-Jupyter Spark数据库访问; java.lang.ClassNotFoun