int does not override Integer in Java

后端 未结 6 913
春和景丽
春和景丽 2020-12-11 02:23

I had a function in Java with method signature

public void myMethod (int someInt, String someString) 

in my abstract class and I had over-

6条回答
  •  Happy的楠姐
    2020-12-11 03:05

    They are absolutely not overridden but overload since the parameters are different. And JVM will choose the method to launch base on this: widen - boxing - var args...

    For example, you have three methods

    void add(long n) {} // call this method 1
    void add(int... n) {} // call this method 2
    void add(Integer n) {} // call this method 3
    

    and when you invoke:

    int a = 5;
    add(a);
    

    the method 1 will be invoked.

提交回复
热议问题