First, the array class type
Representation of an array class type: An array object. GetClass array dimension. Class
1 import Java.lang.reflect.Method;2 3 Public classTest {4 Public Static voidMain (string[] args) {5 Try {6Class c=b.class;7Method Method=c.getmethod ("Show",NewClass[]{string[].class,int[].class});8 //The class type object of an array is only related to the array name and the group dimension9 //such as int[] a={1,2,3} int[] b={2,3,4,5} so a.getclass==b.getclass; Description class type Object is the sameTenMethod.invoke (C.newinstance (),Newobject[]{Newstring[]{" as","SD"},New int[]{1,2}} ); One}Catch(Exception e) { A e.printstacktrace (); - } - } the } - classb{ - Public voidShow (string[] s,int[] r) { - for(inti:r) { +System. out. println (i); - } + for(String t:s) { ASystem. out. println (t); at } - } -}
2. Determine if the object being transmitted is an array
Public void Object { Class c=object. getclass; C.isarray (); // determines if the object being passed is an array }
Reflection of an array