title: Java: Generic method overloading ambiguity
body: <p>Consider the following code:</p>
  
  <pre><code>public class Converter {
  
      public &lt;K&gt; MyContainer&lt;K&gt; pack(K key, String[] values) {
          return new MyContainer&lt;&gt;(key);
      }
  
      public MyContainer&lt;IntWrapper&gt; pack(int key, String[] values) {
          return new MyContainer&lt;&gt;(new IntWrapper(key));
      }
  
  
      public static final class MyContainer&lt;T&gt; {
          public MyContainer(T object) { }
      }
  
      public static final class IntWrapper {
          public IntWrapper(int i) { }
      }
  
  
      public static void main(String[] args) {
          Converter converter = new Converter();
          MyContainer&lt;IntWrapper&gt; test = converter.pack(1, new String[]{"Test", "Test2"});
      }
  }
  </code></pre>
  
  <p>The above code compiles without problems. However, if one changes <code>String[]</code> to <code>String...</code> in both <code>pack</code> signatures and <code>new String[]{"Test", "Test2"}</code> to <code>"Test", "Test2"</code>, the compiler complains about the call to <code>converter.pack</code> being ambiguous.</p>
  
  <p>Now, I can understand why it could be considered ambiguous (as <code>int</code> can be autoboxed into an <code>Integer</code>, thus matching the conditions, or lack thereof, of <code>K</code>). However, what I can't understand is why the ambiguity isn't there if you're using <code>String[]</code> instead of <code>String...</code>.</p>
  
  <p>Can someone please explain this odd behavior?</p>