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翻译的更多相关文章

  1. Scala Option 从官方DOC解析

    Represents optional values. Instances of Option are either an instance of scala.Some or the object N ...

  2. MariaDB官方手册翻译

    MariaDB官方手册 翻译:create database语句(已提交到MariaDB官方手册) 翻译:rename table语句(已提交到MariaDB官方手册) 翻译:alter table语 ...

  3. Genymotion中文手册(官方用户手册翻译)

    目录 1.概述    2 2.特点    2 2.1最擅长于虚拟Android    2 2.2高可控性    2 2.3管理你的设备    2 2.4从Eclipse中开启虚拟设备    3 3.要 ...

  4. HTML5之appcache语法理解/HTML5应用程序缓存/manifest缓存文件官方用法翻译

    习惯性的贴几个参考链接: W3School-HTML 5 应用程序缓存 官方 MDN window.applicationCache 接口文档 官方 MDN 用法示例 看所有的教程不如直接看最原始的官 ...

  5. CF815D Karen and Cards 官方题解翻译

    看到这道题,网上没有中文版的官方题解,于是就自己翻译了一遍. 不是机器翻译,是一个字一个字纯手翻译的,如果有错误欢迎指正. 比如我们有一张卡片,三个参数分别是 a1 = 4, b1 = 2, c1 = ...

  6. Flink-v1.12官方网站翻译-P025-Queryable State Beta

    可查询的状态 注意:可查询状态的客户端API目前处于不断发展的状态,对所提供接口的稳定性不做保证.在即将到来的Flink版本中,客户端的API很可能会有突破性的变化. 简而言之,该功能将Flink的托 ...

  7. Hive官方手册翻译(Getting Started)

    翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的.如有疑问,请参照Hive官方文档对照查看.   内容列表 Cloudera制作的Hive介绍视频 ...

  8. Swift编程语言(中文版)官方手册翻译(进度8.8%)

    翻译着玩,进度会比较慢. 等不及的可以看CocoaChina翻译小组,他们正在组织翻译,而且人手众多,相信会提前很多完成翻译. 原文可以在iTunes免费下载 目前进度 7 JUN 2014: 8.8 ...

  9. Hive官方手册翻译(Getting Started)(转)

    原文:http://slaytanic.blog.51cto.com/2057708/939950 翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的 ...

随机推荐

  1. 正则表达式中常用的模式修正符有i、g、m、s、x、e详解

    正则表达式中常用的模式修正符有i.g.m.s.x.e等.它们之间可以组合搭配使用. 它们的作用如下: //修正符:i 不区分大小写的匹配; //如:"/abc/i"可以与abc或a ...

  2. 在Tomcat中配置MySQL数据源

    打开context.xml文件,路劲为:apache-tomcat-7.0.61\conf,添加如下代码: <Resource auth="Container" driver ...

  3. android开源图表库MPAndroidChart(曲线图、直方图、饼状图)

    github地址:https://github.com/PhilJay/MPAndroidChart 添加依赖: Add the following to your project level bui ...

  4. Dart 基本语法

    ?? // 如果b为null则赋值,否则保持原样 b ??= value; 级联符号.. querySelector('#confirm') // Get an object. ..text = 'C ...

  5. 基于java config的springSecurity--session并发控制

    原作地址:http://blog.csdn.net/xiejx618/article/details/42892951 参考资料:spring-security-reference.pdf的Sessi ...

  6. 阶段3 2.Spring_09.JdbcTemplate的基本使用_2 JdbcTemplate的概述和入门

    先看这张图 1.spring中的JdbcTemplate     JdbcTemplate的作用:         它就是用于和数据库交互的,实现对表的CRUD操作     如何创建该对象:      ...

  7. java:LeakFilling (Mybatis)

    1.实体类属性与数据库中字段名字不一样时,或者起别名时: TbOrderMapper.xml配置文件中,配置resultMap标签: 其它相同的标签也需要配,否则查询不出来对应数据. 2.一对一关联: ...

  8. swagger-ui升级swagger-bootstrap-ui界面好看到起飞

    如果项目已经集成了swagger,只需要在pom.xml添加,如果你的项目没有集成swagger,自行百度或看最下方的链接 swagger-bootstrap-ui是Swagger的前端UI实现,目的 ...

  9. django.db.migrations.exceptions.BadMigrationError: Migration tests in app bl

    这个错误基本上都是 替换文件后才会出现的问题 因为你替换后他的日志文件没有完全替换的话,那么日志对应不到就会出现这样的问题, 一个模糊的处理办法:重新进行数据迁移:首先删除migrations中除去_ ...

  10. Python xlsxwriter库 图表Demo

    折线图 import xlsxwriter # 创建一个excel workbook = xlsxwriter.Workbook("chart_line.xlsx") # 创建一个 ...