如何定义循环类型定义?

Tho*_*ung 6 scala

这不是有效的类型定义:

scala>  type Addable = { def +(subject: Addable) }
<console>:4: error: illegal cyclic reference involving type Addable
        type Addable = { def +(subject: Addable) }
Run Code Online (Sandbox Code Playgroud)

这可以用scala表达吗?

Wal*_*ang 5

不,不能。

在 Scala 语言规范版本 2.7 的第 40 页上:

但是,如果类型别名递归地引用定义的类型构造函数本身,则它是静态错误。也就是说,类型别名type t[tps] = T中的类型 T不能直接或间接引用名称 t