Both static/non-static, fixed/variable parameters are wrapped in an object array for the reflection method.
1 PackageCom.tn.clas;2 3 ImportJava.lang.reflect.Method;4 Importjava.util.Arrays;5 6 Public classClient {7 Public Static voidMain (string[] args)throwsException {8Class<user> Clas=user.class;9Method M=clas.getmethod ("Method", string[].class);TenM.invoke (NULL,Newobject[]{Newstring[]{"AA", "BB", "CC"}});//static methods can omit objects, replace them directly with NULL, or use Clas One AM=clas.getdeclaredmethod ("Method",int[].class);//non-public methods are obtained using declared -M.setaccessible (true);//the non-public method needs to be set to accessible -M.invoke (Clas.newinstance (),New int[]{1,2,3,4,3,2,1}];//non-static methods need to provide the underlying class object the } - } - - classuser{ + Public Static voidMethod (string...strings) { - System.out.println (Arrays.tostring (strings)); + } A at Private voidMethodint... ints) { - System.out.println (arrays.tostring (ints)); - } -}
"Java" Method.invoke (object/null,new object[]{actual parameter) (method bottom)