Passing directly an array initializer to a method parameter doesn't work

后端 未结 3 1268
悲&欢浪女
悲&欢浪女 2020-11-27 08:16
package arraypkg;

import java.util.Arrays;

public class Main
{
    private static void foo(Object o[])
    {
        System.out.printf(\"%s\", Arrays.toString(o));         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 09:02

    foo({1,2}); doesn't tell what type of array it is. So, compiler fails to understand the syntax. All other declarations specify type of array.

提交回复
热议问题