title: Scala error type mismatch
body: <p>I'm trying to find another way of avoiding a type mismatch error that looks more correct than the one I'm using right now.</p>
  
  <p>Considering the list and the function, respectively:</p>
  
  <pre><code>var l = List[Int]()
  
  def append[U](cmd: U) = {
          l = l :+ cmd
  }
  </code></pre>
  
  <p>When interpreting the code above, I'm getting the following error:</p>
  
  <pre><code>&lt;console&gt;:10: error: type mismatch;
   found   : List[Any]
   required: List[Int]
                     l = l :+ cmd
                           ^
  </code></pre>
  
  <p>The way I fixed it, was by modifying the append function to work like this:</p>
  
  <pre><code>  def append[U](cmd: U) = {
      l = (l :+ cmd).asInstanceOf[List[Int]]
    }
  </code></pre>
  
  <p>Is there a way of defining the append function without the use of asInstanceOf?</p>
  
  <p>Trying to be clearer, the goal was to create the class below </p>
  
  <pre><code>abstract class Cstruct{
    type T
    var value: T
    def append[U](value:U)
  }
  </code></pre>
  
  <p>Cstruct should be built in a way that would be possible to define new classes that extends Cstruct but use different data structures for the value T. Like Cseq that uses a List of any type of elements, but should be possible to create a similar one using a Set or a Map.</p>
  
  <pre><code>class Cseq[U] (v: U) extends Cstruct{
    type T = List[U]
    var value: T = List[U](v)
    override def append[U](cmd: U) = {
      value = (value :+ cmd).asInstanceOf[T]
    }
  }
  </code></pre>