gpt4 book ai didi

scala - scala.Singleton 是纯编译器小说吗?

转载 作者:行者123 更新时间:2023-12-01 11:32:38 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com