1

J'ai eu cette question de test pratique pour ma préparation à l'examen OCAJP8. Quelqu'un peut-il expliquer pourquoi les «mauvais» ont tort? Merci.Java varargs - pourquoi cette syntaxe est-elle inacceptable?

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) {} 
+4

Il ne peut y avoir qu'un seul paramètre vararg d'une méthode et il doit s'agir du dernier paramètre. – 4castle

Répondre