title: Abstract type vs. type parameter - where is the difference?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1154571/scala-abstract-types-vs-generics">Scala: Abstract Types vs Generics</a>  </p>
  </blockquote>
  
  
  
  <p>Chapter 20.6 'Abstract types' of 'Programming in Scala' explains the use of an abstract type with an example that ends in the following resulting code:</p>
  
  <pre><code>class Food
  abstract class Animal {
    type SuitableFood &lt;: Food
    def eat(food: SuitableFood)
  }
  
  class Grass extends Food
  class Cow extends Animal {
    type SuitableFood = Grass
    override def eat(food: Grass) {}
  }
  </code></pre>
  
  <p>With these definitions, an object of <code>Cow</code> can not eat a fish:</p>
  
  <pre><code>class Fish extends Food
  val bessy: Animal = new Cow
  bessy eat (new Fish) // Error, type mismatch
  </code></pre>
  
  <p>After reading this good example about the use of an abstract type, I was wondering, why we do not just use a type parameter instead ?</p>
  
  <pre><code>class Food
  abstract class Animal[T &lt;: Food] { 
    def eat(food: T)
  }
  
  class Grass extends Food
  class Cow extends Animal[Grass] {
    override def eat(food: Grass){}
  }
  
  class Fish extends Food
  val bessy: Animal[Grass] = new Cow
  bessy eat (new Fish) // Also ends in a type mismatch error !
  </code></pre>
  
  <p>Where is the difference using type parameter instead of an abstract type here ?</p>