Sealed Class Hierarchies
来源:互联网 发布:淘宝低价销售的危害 编辑:程序博客网 时间:2024/05/22 02:19
A key point about Option
is that there are really only two valid subtypes. Either we have a value, the Some
case, or we don’t, the None
case. There are no other subtypes of Option
that would be valid. So, we would really like to prevent users from creating their own.
Scala has a keyword sealed
for this purpose. Option
is declared like this (eliding some details):
sealed abstract class Option[+A] ... { ... }
The sealed
keyword tells the compiler that all subclasses must be declared in the same source file. Some
and None
are declared in the same file with Option
in the Scala library. This technique effectively prevents additional subtypes of Option
.
Ref
《Programming Scala》
0 0
- Sealed Class Hierarchies
- Dynamic Class与Sealed Class
- Flattening class hierarchies when debugging C#
- 【转载】c# sealed class 的用法
- 【转载】C#之密封类(sealed class)
- Kotlin-14.密封类(sealed class)
- sealed
- sealed
- sealed
- Sealed
- sealed
- Scala-4 - 1 - Lecture 3.1 - Class Hierarchies (25_50)
- 密封类(sealed class)和密封方法(sealedmethod)
- sealed class 做函数扩展的方法,dotnet 3.0
- Kotlin Reference (十三) Data Class and Sealed Classes
- cache hierarchies
- cache hierarchies
- C++ - 阻止派生类(derived class)重新定义虚函数(final&sealed)
- 浅析Java Reflection Facility(反射机制)
- Welcome to the World of Ingress
- 证明的思路 —— 数形结合
- 同一个项目在me10上完美运行,在me14上却出抛异常
- c预处理命令
- Sealed Class Hierarchies
- 自然语言处理常用数据集
- 关于select2的使用——解决点击瞬间下拉框消失的问题
- 从输入URL到页面加载发生了什么
- 使用python爬虫爬取百度手机助手网站中app的数据
- Neural Networks and Deep Learning CH1
- Android中引用资源的方法总结
- 对极几何基本概念
- codeforces 373div1 Sasha and Array 矩阵+线段树