Method Overloading for null argument

前端 未结 7 735
悲哀的现实
悲哀的现实 2020-11-21 13:48

I have added three methods with parameters:

public static  void doSomething(Object obj) {
    System.out.println(\"Object called\");
}

public static  void d         


        
7条回答
  •  春和景丽
    2020-11-21 14:12

    null is a valid value for any of the three types; so the compiler cannot decide which function to use. Use something like doSomething((Object)null) or doSomething((Integer)null) instead.

提交回复
热议问题