scala.Singleton是纯编译器小说吗? [英] Is scala.Singleton pure compiler fiction?

查看:125
本文介绍了scala.Singleton是纯编译器小说吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scala语言规范在第3.2.1节中说:

The Scala Language Specification says under §3.2.1:

稳定类型是单例 类型或声明为 性状scala.Singleton的子类型.

A stable type is either a singleton type or a type which is declared to be a subtype of trait scala.Singleton.

在源代码,ScalaDoc和二进制jar文件中都找不到scala.Singleton.

I couldn't find scala.Singleton neither in the sources, in ScalaDoc nor in the binary jar file.

尝试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住在哪里,目的是什么?

Where does scala.Singelton live and what's its purpose?

推荐答案

最终在此找到了一些东西:

Finally found something on this:

Singleton类型本质上是一个 存在的编码技巧 价值观. IE.

The type Singleton is essentially an encoding trick for existentials with values. I.e.

T forSome { val x: T } 

变成了

[x.type := X] T forSome { type X <:T with Singleton } 

来源: http://scala-programming-language.1934581.n4 .nabble.com/scala-Singleton-td1940630.html

这篇关于scala.Singleton是纯编译器小说吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆