[英]For “trait Queue[T]”, is `Queue` a type?
Defined a trait in scala: 在scala中定义了一个特征:
trait Queue[T]
Is Queue
a type? Queue
是一种类型吗? Or something else, eg a type constructor? 或其他东西,例如类型构造函数?
From http://artima.com/pins1ed/type-parameterization.html#19.3 of book "programming in scala", it says: 从“scala编程”一书的http://artima.com/pins1ed/type-parameterization.html#19.3开始 ,它说:
Queue, as defined in Listing 19.4, is a trait, but not a type. 清单19.4中定义的队列是一个特征,但不是一个类型。
But someone thinks it is a type, so I totally confused. 但有人认为这是一种类型,所以我完全糊涂了。
Is it a type or not? 这是一种类型吗? If not, what it is exactly? 如果没有,那究竟是什么?
The following sentence answers your question: 以下句子回答了你的问题:
Queue, as defined in Listing 19.4, is a trait, but not a type. 清单19.4中定义的队列是一个特征,但不是一个类型。 Queue is not a type because it takes a type parameter. 队列不是类型,因为它需要一个类型参数。
We call Queue
a generic type . 我们将Queue
称为泛型类型 。 You cannot use it alone, otherwise the compiler will complain 你不能单独使用它,否则编译器会抱怨
trait Queue takes type parameters trait Queue采用类型参数
Try this: 试试这个:
type Q1 = Queue[Int]
//type Qwrong = Queue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.