Overloading function using varargs

前端 未结 3 626
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 01:20

This will not compile:

public class Methods
{

    public static void method(Integer... i)
    {
        System.out.print(\"A\");
    }

    public static vo         


        
3条回答
  •  长发绾君心
    2021-01-19 01:48

    Multiple arguments must be passed in an array, but the varargs hides the process. In the above varargs method, parameter acts as an int array with a reference name. So if you change it to:

        public static void main(String args[])
        {
            int[] s = {7};
            method(s);
        }
    

    first class will compile and work properly.

提交回复
热议问题