Variable argument function ambiguity

前端 未结 4 1196
鱼传尺愫
鱼传尺愫 2021-01-12 12:58
   public static void main(String[] args) {
       System.out.println(fun(2,3,4));
     }
   static int fun(int a,int b,int c)
   {
     return 1;
   }
   static int         


        
4条回答
  •  忘掉有多难
    2021-01-12 13:03

    If you test this expressions:

        System.out.println(fun(2,3,4));
        System.out.println(fun(2,3));
        System.out.println(fun(2,3,4,7));
    

    The output is

    1
    0
    0
    

    The Java compiler first checks for a method whose declaration matchs the exact parameters of the invocation, and otherwise, it searches for the alternative method matching.

提交回复
热议问题