difference fn(String… args) vs fn(String[] args)

前端 未结 6 935
情书的邮戳
情书的邮戳 2020-11-28 03:47

Whats this syntax useful for :

    function(String... args)

Is this same as writing

    function(String[] args) 
<         


        
6条回答
  •  野性不改
    2020-11-28 04:41

    with varargs (String...) you can call the method this way:

    function(arg1);
    function(arg1, arg2);
    function(arg1, arg2, arg3);
    

    You can't do that with array (String[])

提交回复
热议问题