Overloading avec var args
Bonjour,
J'ai lu sur JavaRanch le topic suivant:
http://www.coderanch.com/t/501804/ja...ed-overloading
... et j'avoue que je ne comprends toujours pas l'explication de l'appel à la méthode
Code:
1 2 3 4
| //methObject
static void overloading(Object... o) {
System.out.println("Object Var-Args");
} |
(dans le contexte du post 1).
Dans un des posts qui suivent, un intervenant dit:
Citation:
Object... method has argument type of Object[] and so it can be called with String[] without using variable arity invocation. Non varargs call is always preffered against varargs call so the Object... method will be used.
Ce que je ne comprends pas est pourquoi "methObject" serait appelée "without using variable arity invocation".
Je crois qu'il sous entend que la nuance vient du fait qu'une méthode ayant pour argument soit Object[] soit Object peut recevoir un paramètre de type String[] (qui est un tableau d'Objects mais aussi simplement un Object). Je suis d'accord sur ce point mais où cela mène t-il?
Merci vivement de votre aide.