class Overload{
public static void main(String args[]) {
int[] number={1,2,3,4,5,6,7,8,9,10};
int [] num={1,2,3,4,5};
int i;
int sum=0;
sum = f(number);
int sum1= f(num);
System.out.println("The sum is" +sum + ".");
System.out.println("The sum is" +sum1 + ".");
}
public static int f(int[] value) {
int i, total = 0;
for(i=0; i<10; i++) {
total = total + value[ i ];
}
return (total);
}
public static int f(int... x) {
int i, total = 0;
for(i=0; i<10; i++) {
total = total + x[ i ];
}
return (total);
}
}
在编译上述程序时,我收到错误消息
C:\Program Files\Java\jdk1.7.0_09\bin>javac Overload.java Overload.java:30:错误:不能在 Overload 中同时声明 f(int...) 和 f(int[]) 公共静态int f(int ... x)