This question already has answers here:
Java “params” in method signature?
                                
                                    (3个答案)
                                
                        
                2年前关闭。
            
        

我的OCAJP8考试准备中有这个练习题。有人可以解释为什么“错”错了吗?谢谢。

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只能在最终参数位置使用。

关于java - Java varargs-为什么这些语法 Not Acceptable ? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43814905/

10-12 02:37