3

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?

Freewind
  • 193,756
  • 157
  • 432
  • 708

1 Answers1

4

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
Arie Xiao
  • 13,909
  • 3
  • 31
  • 30
  • Not quite correct. You can use `Queue` without type parameter in any place that expects a higher kinded type. – drexin Jun 18 '14 at 19:39