Farruh Habibullaev Farruh Habibullaev - 11 months ago 52
Java Question

Java overloading - why are int and Integer the same?

Why does JAVA see Integer object and int primitive type the same when overloading for example:

ClassOne {

void myMethod(int number){


void myMethod(Integer number) {



It does not see them as the same, it just treats them the same. If you want to explicitly use an Integer you'll have to explicitly cast it.

public void testOverload() {
    test123(123); //Logs "int-Method"
    test123((Integer)123); //Logs "Integer-Method"

private void test123(int ix) {

private void test123(Integer ix) {