Scala Language Specification在 §3.2.1 下说:
A stable type is either a singleton type or a type which is declared to be a subtype of trait scala.Singleton.
我找不到
scala.Singleton
既不在源代码中,也不在 ScalaDoc 中,也不在二进制 jar 文件中。尝试 REPL 结果:
scala> class Foo extends Singleton
<console>:9: error: illegal inheritance from final trait Singleton
class Foo extends Singleton
^
<console>:9: error: illegal inheritance; superclass Any
is not a subclass of the superclass Object
of the mixin trait ScalaObject
class Foo extends Singleton
^
在哪里
scala.Singelton
生活,它的目的是什么?
最佳答案
终于在这方面找到了一些东西:
The type Singleton is essentially an encoding trick for existentials with values. I.e.
T forSome { val x: T }
is turned into
[x.type := X] T forSome { type X <:T with Singleton }
来源:http://scala-programming-language.1934581.n4.nabble.com/scala-Singleton-td1940630.html
关于scala - scala.Singleton 是纯编译器小说吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118038/