I had this practice test question for my OCAJP8 exam preparation. Can someone please explain why the 'Wrong' ones are wrong? Thanks.
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) {}
To quote from https://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
Varargs can be used only in the final argument position.