title: Ambiguous Reference to overloaded definition - One vs Two Parameters
body: <p>Given the following companion object with overloaded versions of <code>apply</code>:</p>
  
  <pre><code>object List {
    def apply[T](): List[T] = new Nil
    def apply[T](x1: T): List[T] = new Cons(x1, new Nil)
    def apply[T](x1: T, x2: T): List[T] = new Cons(x1, new Cons(x2, new Nil))
    def apply[T](elems: T*): List[T] = 
      elems.foldRight(List[T])((elem, l) =&gt; new Cons(elem, l))
  }
  </code></pre>
  
  <p>And the two instantiations</p>
  
  <pre><code>List(1) // Error - Ambiguity 
  List('a', 'b') // Works fine
  </code></pre>
  
  <p>scalac complains about the first instantiation (<strong>ambiguous reference to overloaded definition</strong>) because both the single argument and the varargs method are <a href="https://stackoverflow.com/a/2161551/664577">equally <em>specific</em></a>. </p>
  
  <p>Searching stackoverflow I've found that it is possible to <a href="https://stackoverflow.com/a/14290755/6645770">force the single argument method</a>. <code>List[Int](1)</code> will make the compiler use <code>def apply[T](x1: T)</code>.</p>
  
  <p>My question is why does the second instantiation match <code>def apply[T](x1: T, x2: T)</code> without extra "hints"? In other words, why is the two argument method more <em>specific</em> than the varargs method where the single argument method isn't?</p>