【发布时间】:2021-02-19 23:41:10
【问题描述】:
下面的sn-p解释了我的困惑:
scala> case class fellow[A, B](name:A, age:B)
class fellow
scala> :t -v fellow
// Type signature
fellow.type
// Internal Type structure
TypeRef(
pre = ThisType(class $iw)
TypeSymbol(class fellow extends Serializable)
)
scala> :kind -v fellow.type
fellow.type's kind is A
*
This is a proper type.
scala> :kind -v fellow
fellow's kind is F[A1,A2]
* -> * -> *
This is a type constructor: a 1st-order-kinded type.
为什么 Fellow.type 不同于 Fellow(作为一种类型) 我不明白为什么这两种类型不同,为什么 :t -v 返回 Fellow.type ?
在这个小实验之后写,我检查了 List,发现它是一样的
scala> :kind -v List
List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.
scala> :kind -v List.type
scala.collection.immutable.List.type's kind is A
*
This is a proper type.
那么 .type 到底是什么?它从何而来 ?它与其他有什么不同...特征名称,类名称
【问题讨论】:
-
即类的伴生对象的类型。例如 Nil 的类型是
Nil.type- 请注意,.type语法可用于访问值的单例类型。