Defined a trait in scala:
trait Queue[T]
Is Queue
a type? Or something else, eg a type constructor?
From http://artima.com/pins1ed/type-parameterization.html#19.3 of book "programming in scala", it says:
Queue, as defined in Listing 19.4, is a trait, but not a type.
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. Queue is not a type because it takes a type parameter.
We call Queue
a generic type . You cannot use it alone, otherwise the compiler will complain
trait Queue takes type parameters
Try this:
type Q1 = Queue[Int]
//type Qwrong = Queue
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.