title: involved usage of overridden methods, type bounds, and... type erasure
body: <p>This is really an involved scenario. Vertices and edges are added to a graph. A convenience method for adding a variable amount of them has been desired. Any way I try to make the latter api requirement happen I fail over type erasure, or a compiler failure to resolve which overridden method needs to be called. Here's the code intent expressed through one failed variation:</p>
  
  <pre><code>/*
   * API definition
   */
  abstract class AbstractGraph[ID, Vertex &lt;: AbstractVertex[ID], Edge &lt;: AbstractEdge[ID]]  {
  
    def += (vertex: Vertex): AbstractGraph[ID, Vertex, Edge] 
  
    def += (edge: Edge): AbstractGraph[ID, Vertex, Edge] 
  
    def ++=(inputs: Addable*): AbstractGraph[ID, Vertex, Edge] = {
      inputs.foreach(i =&gt; i match {
        case v : AbstractVertex[ID] =&gt; this += v
        case e : AbstractEdge[ID]   =&gt; this += e
      })
      this
    } 
  }
  
  
  abstract trait Addable
  
  /*
   * trait to be mixed in by user code for making their nodes graph friendly
   */
  abstract trait AbstractVertex[ID] extends Addable {  
    val id: ID 
  } 
  
  /*
   * trait to be mixed in by user code for making their edges graph friendly
  */
  abstract trait AbstractEdge[ID] extends Addable {
    val id1: ID
    val id2: ID
  }
  </code></pre>
  
  <p>This intent demonstrating variation above, fails with the following:</p>
  
  <pre><code>overloaded method value += with alternatives:
  (edge: Edge)org.canve.simpleGraph.AbstractGraph[ID,Vertex,Edge] &lt;and&gt;
  (vertex: Vertex)org.canve.simpleGraph.AbstractGraph[ID,Vertex,Edge]
  cannot be applied to (org.canve.simpleGraph.AbstractVertex[ID])
    case v : AbstractVertex[ID] =&gt; this += v
                                        ^
  
  overloaded method value += with alternatives:
  (edge: Edge)org.canve.simpleGraph.AbstractGraph[ID,Vertex,Edge] &lt;and&gt; (vertex: Vertex)org.canve.simpleGraph.AbstractGraph[ID,Vertex,Edge]
  cannot be applied to (org.canve.simpleGraph.AbstractEdge[ID])
    case e : AbstractEdge[ID]   =&gt; this += e
                                        ^
  </code></pre>
  
  <p>Believe me this has been my most elegant attempt... even though it was silly to assume the compiler would infer the appropriate overloaded <code>+=</code> method from the type bound of its signature's argument type. Practically every other variation I try hits a type erasure wall in some place.</p>
  
  <p>Can you suggest a way to implement the <code>++=</code> method after all?</p>
  
  <p>Oddly enough a <a href="https://stackoverflow.com/questions/1964938/case-classes-with-an-upper-type-bound">similarly titled question</a> also came from the realm of graphs ;(</p>
  
  <p>Call me obsessive but not being able to materialize this api is really disappointing so I'd appreciate your help and insight. Of course I could split ++= to a vertices only method and an edges only method, but that alone will... type erasure fail. I could go with different names as well and that might lead the way to fallback from this clean api design - but that excludes providing an elegant api to my library. </p>