Java varargs - 为什么这些语法不可接受?
Java varargs - why are these unacceptable syntax?
我在准备 OCAJP8 考试时遇到了这个练习题。有人可以解释为什么 'Wrong' 是错误的吗?谢谢
Which of the following compile?
Response
Wrong
public void moreD(String... values, int... nums) {}
Wrong
public void moreF(String... values, int[] nums) {}
Correct
public void moreB(String values, int... nums) {}
Correct
public void moreG(String[] values, int[] nums) {}
Correct
public void moreA(int... nums) {}
Wrong
public void moreC(int... nums, String values) {}
引用自https://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
Varargs can be used only in the final argument position.
我在准备 OCAJP8 考试时遇到了这个练习题。有人可以解释为什么 'Wrong' 是错误的吗?谢谢
Which of the following compile?
Response
Wrong
public void moreD(String... values, int... nums) {}
Wrong
public void moreF(String... values, int[] nums) {}
Correct
public void moreB(String values, int... nums) {}
Correct
public void moreG(String[] values, int[] nums) {}
Correct
public void moreA(int... nums) {}
Wrong
public void moreC(int... nums, String values) {}
引用自https://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
Varargs can be used only in the final argument position.