Defined a trait in scala:
trait Queue[T]
Is Queue a type? Or something else, e.g. 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With