反射创建数组:
在Java的反射机制中,通过 数组的 class 对象的getComponentType()方法可以取得一个数组的Class对象, 通过Array.newInstance()可以反射生成数组对象,看示例代码:
char[] charArray = (char [])Array.newInstance(char[].class.getComponentType(), 100);
System.out.println("the length of the charArray is :" + charArray.length);
String[] strArray = (String [])Array.newInstance(String[].class.getComponentType(), 10);
System.out.println("the length of the strArray is :" + strArray.length);
注意:它是数组class的方法,不是数组class用不了!