title: Why does autoboxing make some calls ambiguous in Java?
body: <p>I noticed today that auto-boxing can sometimes cause ambiguity in method overload resolution. The simplest example appears to be this:</p>
  
  <pre><code>public class Test {
      static void f(Object a, boolean b) {}
      static void f(Object a, Object b) {}
  
      static void m(int a, boolean b) { f(a,b); }
  }
  </code></pre>
  
  <p>When compiled, it causes the following error:</p>
  
  <pre><code>Test.java:5: reference to f is ambiguous, both method
      f(java.lang.Object,boolean) in Test and method
      f(java.lang.Object,java.lang.Object) in Test match
  
  static void m(int a, boolean b) { f(a, b); }
                                    ^
  </code></pre>
  
  <p>The fix to this error is trivial: just use explicit auto-boxing:</p>
  
  <pre><code>static void m(int a, boolean b) { f((Object)a, b); }
  </code></pre>
  
  <p>Which correctly calls the first overload as expected.</p>
  
  <p>So why did the overload resolution fail? Why didn't the compiler auto-box the first argument, and accept the second argument normally? Why did I have to request auto-boxing explicitly?</p>