why primitive type will call first rather than wrapper classes?

Posted by kandarp on Stack Overflow See other posts from Stack Overflow or by kandarp
Published on 2010-12-24T03:53:33Z Indexed on 2010/12/24 4:54 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

Hello EveryOne,

public class A {

   public void test(Integer i) {
       System.out.println("In Wrapper Method");
   }

   public void test(int i) {
       System.out.println("In primitive Method");
   }

   public static void main(String args[]) {
       A a = new A();
       a.test(5);
   }


}

When I will call test method from main and pass integer argument, then it will call the method which accept primitive type as argument. I just want to know that why it call primitive type method rather than the method who accepts wrapper class as argument? Is there any rule, which java follow to call methods?

Thanks,

© Stack Overflow or respective owner

Related posts about java

Related posts about class