java基础
package Integer;
public class OverloadingVarargs
{
static void f(Character... args)
{
System.out.println("first");
for(Character c:args)
{
System.out.print(" "+c);
}
System.out.println();
}
static void f(Integer... args)
{
System.out.println("second");
for(Integer i:args)
{
System.out.print(" "+i);
}
System.out.println();
}
static void f(long... args)
{
System.out.println("thred");
}
public static void main(String[] args) {
f('a','b','c');
f(1);
f(2,1);
f(0);
f(0l);
}
}
如上代码所示,我在调用静态方法f()时候,在main中最后一个f()没有报错,而其他的都报错 了,不知道是为什么,但是我把可变参数直接改成[]数组就对了,这是什么原因。