Method Overloading for null argument

前端 未结 7 866
悲哀的现实
悲哀的现实 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:24

    class Sample{
      public static void main (String[] args) {
           Sample s = new Sample();
           s.printVal(null);
    
        } 
        public static void printVal(Object i){
            System.out.println("obj called "+i);
        }
    
        public static void printVal(Integer i){
            System.out.println("Int called "+i);
        }
    }
    

    The output is Int called null and so ambiguity is with char[] and Integer

提交回复
热议问题