scala类型系统:18) 不稳定(volatile)类型

volatile type,中文称为不稳定类型或易变类型,指编译器不能确定其成员不会发生改变的类型(一个例子是在一个抽象类中定义了一个抽象的类型),在scala语言规范里描述有4种情况可能满足:

1 对于复合类型

`T1 with ... Tn {R} `若该复合类型满足下面情况之一,即为不稳定类型

1.1 `T2,...,Tn` 中有一个类型参数或抽象类型
1.2  T1 是一个抽象类型,并且 R 或 Tj(j>1) 提供了一个抽象成员
1.3  `T1,...,Tn` 中有一个是单例类型

2 对于type designator(类型标识符,比如用class或type关键字定义的类型)

A type designator is volatile if it is an alias of a volatile type, or if it designates a type parameter or abstract type that has a volatile type as its upper bound.

3 对于单例类型

A singleton type p.type is volatile, if the underlying type of path p is volatile.

4 对于存在类型

 如果`T`是不稳定类型,则 `T forSome { Q }` 也是不稳定类型

scala类型系统:18) 不稳定(volatile)类型》上有4个想法

  1. 不稳定类型这个概念引入的原因与目的是什么? 能举写例子么?

发表评论

电子邮件地址不会被公开。 必填项已用*标注