title: using trait as generic interface in scala
body: <p>I've got a pseudo-generic class factory that I'm using for DAO purposes. The operational model is pretty straightforward:<br> 
  1) the factory is instantiated with knowledge of a specific DAO-object "T"ype<br>
  2) it then creates an internal instance of T<br>
  3) it should call a trait-contracted function of T<br>
  4) finally, return the instance of T (assuming all goes well)<br></p>
  
  <p>It looks like this:</p>
  
  <pre><code>class DAOFactory[T](implicit m: Manifest[T]) {
     def obj = m.runtimeClass.asInstanceOf[Class[T]]
     def doFoo(): Option[Any] = {
         val dao = obj.asInstanceOf[DAO]     // (A) this line will crash
         println(obj.toString())    // some.object.called.DAOTodo
         // val bar = dao.doSomethingSmart(now)   &lt;--- ALL DAO-derived classes implement this function
         return Some(obj) // error-catching excluded for brevity 
     }
  }
  </code></pre>
  
  <p>It is used like this: <br>
      val f = new DAOFactory[DAOTodo] <br>
      val shinyNewObject = f.doFoo()   // never gets here.</p>
  
  <p>Where 'DAOTodo' is, in fact, a class that implements the DAO trait: </p>
  
  <pre><code>class DAOTodo extends DAO {
     def doSomethingSmart(when: Whenever) = {...}
  }
  </code></pre>
  
  <p>Q: what needs to be done at point "A" to use DAO as the interface to the "doSomethingSmart" function of "obj"?</p>
  
  <p>Thanks in advance. </p>
  
  <p><strong>ANSWER:</strong> 
  Aside from the code modification as outlined in the answer below, this was not running as predicted due to the fact that the lineage for the classes being created (within the factory) had a primary constructor that was not being fulfilled. Creating an additional zero-param constructor resolved the issue.          </p>