Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
C HAPTER 19 ยท Type Parameterization class. The code in Listing 19.4 implements this design. There's a trait Queue , which declares the methods head , tail , and enqueue . All three methods are implemented in a subclass QueueImpl , which is itself a private inner class of object Queue . This exposes to clients the same information as before, but using a different technique. Instead of hiding individual constructors and methods, this version hides the whole implementation class. 19.3 Variance annotations 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. As a result, you cannot create variables of type Queue : scala> def doesNotCompile(q: Queue) {} <console>:5: error: trait Queue takes type parameters def doesNotCompile(q: Queue) {} ^ Instead, trait Queue enables you to specify parameterized types, such as Queue[String] , Queue[Int] , or Queue[AnyRef] :