Scala Nothing 从官方DOC翻译
Nothing is - together with scala.Null - at the bottom of Scala's type hierarchy.
Scala中的Nothing和Null两个类位于Scala类型继承树的底部。
Nothing is a subtype of every other type (including scala.Null); there exist no instances of this type.
Nothing是Scala中其他任何类(包含Null)的子类,Nothing不能再被子类化。
Although type Nothing is uninhabited, it is nevertheless useful in several ways.
Nothing在几个方面发挥作用。
For instance, the Scala library defines a value scala.collection.immutable.Nil of type List[Nothing].
比如,Scala用Nil定义空集合,而Nil其实是List[Nothing]
Because lists are covariant in Scala, this makes scala.collection.immutable.Nil an instance of List[T], for any element of type T.
因为Scala中的列表是协变的,所以Nil是任何泛型列表List[T]的实例,而只有Nothing是所有类型T的子类,所以在
定义Nil的时候,Nothing就发挥了自己的用途。
Another usage for Nothing is the return type for methods which never return normally. One example is method error in scala.sys, which always throws an exception.
Nothing也被用在当方法不正常返回的场合。比如sys.error("err")。它的源码是:
def error(message: String): Nothing = throw new RuntimeException(message)
这个方法不会返回Unit,因为它不是正常结束,是异常中断了。
Scala Nothing 从官方DOC翻译的更多相关文章
- Scala Option 从官方DOC解析
Represents optional values. Instances of Option are either an instance of scala.Some or the object N ...
- MariaDB官方手册翻译
MariaDB官方手册 翻译:create database语句(已提交到MariaDB官方手册) 翻译:rename table语句(已提交到MariaDB官方手册) 翻译:alter table语 ...
- Genymotion中文手册(官方用户手册翻译)
目录 1.概述 2 2.特点 2 2.1最擅长于虚拟Android 2 2.2高可控性 2 2.3管理你的设备 2 2.4从Eclipse中开启虚拟设备 3 3.要 ...
- HTML5之appcache语法理解/HTML5应用程序缓存/manifest缓存文件官方用法翻译
习惯性的贴几个参考链接: W3School-HTML 5 应用程序缓存 官方 MDN window.applicationCache 接口文档 官方 MDN 用法示例 看所有的教程不如直接看最原始的官 ...
- CF815D Karen and Cards 官方题解翻译
看到这道题,网上没有中文版的官方题解,于是就自己翻译了一遍. 不是机器翻译,是一个字一个字纯手翻译的,如果有错误欢迎指正. 比如我们有一张卡片,三个参数分别是 a1 = 4, b1 = 2, c1 = ...
- Flink-v1.12官方网站翻译-P025-Queryable State Beta
可查询的状态 注意:可查询状态的客户端API目前处于不断发展的状态,对所提供接口的稳定性不做保证.在即将到来的Flink版本中,客户端的API很可能会有突破性的变化. 简而言之,该功能将Flink的托 ...
- Hive官方手册翻译(Getting Started)
翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的.如有疑问,请参照Hive官方文档对照查看. 内容列表 Cloudera制作的Hive介绍视频 ...
- Swift编程语言(中文版)官方手册翻译(进度8.8%)
翻译着玩,进度会比较慢. 等不及的可以看CocoaChina翻译小组,他们正在组织翻译,而且人手众多,相信会提前很多完成翻译. 原文可以在iTunes免费下载 目前进度 7 JUN 2014: 8.8 ...
- Hive官方手册翻译(Getting Started)(转)
原文:http://slaytanic.blog.51cto.com/2057708/939950 翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的 ...
随机推荐
- Scala学习(二)——高级特性
apply() 方法 apply方法是Scala提供的一个语法糖 类名+括号,调用对象的apply方法 对象名+括号,调用类的apply方法 对apply方法的简单测试:(其中,带 new -- cl ...
- 三、smarty--变量调节器(修改器)
变量调节器(修改器) 作用: 1. 从PHP中分配个模板的变量 2. 需要模板中对变量在输出前进行处理 3. 处理方式就是使用“函数” 4. 在smarty3中可以直接调用到PHP的函数 5. ...
- Linux高级调试与优化——Address Sanitizer
Address Sanitizer ASAN最早可以追溯到 LLVM 的 sanitizers项目(https://github.com/google/sanitizers),这个项目包含了Addre ...
- web安全之如何防止CSRF跨站请求伪造(转载)
https://www.cnblogs.com/blibli/p/7658168.html CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click ...
- N2RR
一.背景 氨(NH 3)是一种新兴的能量载体,在液氨中含有17.6%(重量)的氢,而在甲醇中的含量为12.5%(重量),很可能成为未来氢能经济的有希望的候选者.然而,如果基于NH 3的肥料不足以养活世 ...
- 【8】ie css hack
1. "\9" IE6/IE7/IE8/IE9/IE10都生效 "\0" IE8/IE9/IE10都生效,是IE8/9/10的hack "\9 ...
- vim 编辑提示swap file already exists 解决方法
linux服务器上编辑 .ini 文件时卡死,关闭连接工具后重新进入操作该 .ini 文件时,会提示: E325: ATTENTION Found a swap file by the name &q ...
- python3.5以后venv创建/激活/退出虚拟环境
1.创建虚拟环境 $ python3 -m venv <环境名称> 2.激活虚拟环境 $ source <环境名称>/bin/activate 3.关闭虚拟环境 $ deact ...
- Multi-Object-Edit With Django FormSets
I had to write a multi-object edit table the other day for a Django project and as such I dove into ...
- ELK+Kafka
kafka:接收java程序投递的消息的日志队列 logstash:日志解析,格式化数据为json并输出到es中 elasticsearch:实时搜索搜索引擎,存储数据 kibana:基于es的数据可 ...