title: The method is ambiguous for the type Error
body: <p>I am trying to understand how Overloading in JAVA works and trying to get grasp of various overloading rules that are applied in case of widening, autoboxing and varargs in JAVA. I am not able to understand what is happening in the following scenario:</p>
  
  <pre><code> package package1;
  
   public class JustAClass {
       public static void add(int a, long b) {
           System.out.println("all primitives");
       }
  
     //public static void add(Integer a, long b) {
     //     System.out.println("Wraper int, primitive long");
     //}
  
       public static void add(int a, Long b) {
           System.out.println("Primitive int, Wrapper long");
       }
  
       public static void add(Integer a, Long b){
           System.out.println("All wrapper");
       }
  
       public static void main(String[] args) {
          int a = 10;
          Integer b = 10;
          long c = 9;
          Long d = 9l;
  
          add(a,c);
          add(a,d);
          add(b,c);
          add(b,d);
   }
  
  }
  </code></pre>
  
  <p>At this point, I get a compilation error at the third invocation of the <code>add</code> method saying <code>The method  is ambiguous for the type Error</code> .
  Why is this so? What are the rules for determining which invocation of method will work? What is exactly happening in the following case? 
  I feel that <code>fourth</code> overloaded add method should work. Please help me understand the concept behind this.</p>