【问题标题】:Why is T a type projection of this.type in expanded type designator C.this.type#T为什么 T 是扩展类型指示符 C.this.type#T 中 this.type 的类型投影
【发布时间】:2020-11-22 16:37:45
【问题描述】:

SLS 3.2.5 Type Designators表示

trait C {
  type T
  val x: T
}

扩展到

trait C {
  type T
  val x: C.this.type#T
}

我熟悉单例类型中的.type 表示法,但我不确定它如何转换为C.this.type#T。例如。 this.type 部分试图传达的只是说 C#T 是什么?

【问题讨论】:

    标签: scala types terminology


    【解决方案1】:

    在 Scala 规范中,主要概念是类型投影而不是依赖于路径的类型。

    并且依赖于路径的类型是根据类型投影(和单例类型)定义的。

    例如对于val c: C,类型c.T 定义为c.type#T

    c.x 的类型为c.T 又名c.type#T

    内部特征C 这种类型(当实例c 不固定时)可以称为T aka this.T aka this.type#T aka C.this.T aka C.this.type#T

    【讨论】:

      猜你喜欢
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      相关资源
      最近更新 更多