title: Java overloading: reference to call ambiguous
body: <p>Consider the following example code:</p>
  
  <pre><code>public class TestClass {
  
      public void doSth(String str, String l, Object... objects) {
          System.out.println("A");
      }
  
      public void doSth(String str, Object... objects) {
          System.out.println("B");
      }
  
  }
  </code></pre>
  
  <p>When I now call <code>new TestClass().doSth("foo", "bar")</code> I get the expected result <code>A</code>. But if I change the method signature of the first method by chaging the parameter <code>l</code> to a primitive type:</p>
  
  <pre><code>public class TestClass {
  
      public void doSth(String str, long l, Object... objects) {
          System.out.println("A");
      }
  
      public void doSth(String str, Object... objects) {
          System.out.println("B");
      }
  
  }
  </code></pre>
  
  <p>calling <code>new TestClass().doSth("foo", 2L)</code> will yield a <code>reference to call ambiguous</code> compile time error. </p>
  
  <p>I thought about that one for some time now and also consulted <a href="https://stackoverflow.com/questions/14053596/compiler-error-reference-to-call-ambiguous">this stackoverflow question</a>, but I was unable to understand why this happens. In my opinion the <code>doSth("foo", 2L)</code> is more specific to the <code>doSth(String string, long l, Object... obj)</code> signature and should allow the compiler to also come to this conclusion.</p>