Do not say nonsense, directly on the code:
1 Packagemytest;2 3 Importjava.util.List;4 5 Public classTestClass {6 7 Public voidMethod (list<object>list) {8System.out.println ("Method with param list<object> invoked!");9 }Ten One Public voidmethod (Object ... objects) { ASystem.out.println ("Method with param Object ... invoked!"); - } -}
1 Packagemytest;2 3 Importjava.util.ArrayList;4 Importjava.util.List;5 6 Public classMain {7 8 Public Static voidMain (string[] args) {9list<string> list =NewArraylist<string>();TenList.add ("AA"); OneList.add ("BB"); AList.add ("CC"); - -TestClass t =NewTestClass (); the - T.method (list); - } - +}
The main method executes the result:
Method with param Object ... invoked!
Why an overloaded method is a parameter of LIST<OBJECT> A parameter is an object ..., the calling method has a parameter type of LIST<STRING>, and the actual execution of the argument is object ... Method?
"Help" Java variable length parameter method call problem