title: Scala typing: "Expected _$1, got T"
body: <p>I have a Lift project with mixed Java-Scala code. The project has a JPA backend written in Java with EclipseLink, which is accessed by the Scala side, which uses Lift and Lift-NG. </p>
  
  <p>On the Java side, I have the following relevant interfaces:</p>
  
  <pre><code>interface IEntity
  
  interface IDAO&lt;T extends IEntity&gt; {
      void persist(T t);
  }
  </code></pre>
  
  <p>On the Scala side, I have the following:</p>
  
  <pre><code>abstract class Binding[T &lt;: IEntity] extends NgModel {
      def unbind: T
  }
  
  class BasicService[B &lt;: Binding[_ &lt;: IEntity]](serviceName: String, dataAccessObject: IDAO[_ &lt;: IEntity]) {
      def persist(binding : B): Unit = {
          val entity = binding.unbind
          dataAccessObject.persist(entity)
      }
  }
  </code></pre>
  
  <p>The purpose of this hierarchy is to let me create Service instances which handle a given Binding for entity E, which can also receive and use an appropriate DAO created to handle type E. For example:</p>
  
  <pre><code>// Java side
  class Todo implements IEntity
  
  class TodoManager implements IDAO&lt;Todo&gt;
  
  // Scala side
  case class TodoBinding extends Binding[Todo] {
      override def unbind: Todo = new Todo()
  }
  object HelloWorld extends BasicService[TodoBinding]("todoService", new TodoManager) 
  </code></pre>
  
  <p>My problem is a compilation error that occurs inside the persist method of BasicService. On the last line, I get this:</p>
  
  <pre><code>Type mismatch: expected _$1, actual: IEntity
  </code></pre>
  
  <p>As I am a bit inexperienced with Scala, I might be missing something very obvious with the type system, but I genuinely cannot figure this out. How can I work around this error?</p>