Class<?> getComponentType()方法是Class中的方法,可以返回表示数组类型的Class。 boolean isPrimitive()用来判断指定的Class类是否为一个基本类型。 例:
String [] arr = new String[10]; String str = ""; System.out.println(arr.getClass()); // 数组的String 类 System.out.println(str.getClass()); // 非数组的String 类 System.out.println(arr.getClass().getComponentType()); // String类 System.out.println(str.getClass().getComponentType()); // 得到null值,因为str不是数组 System.out.println(arr.getClass().getComponentType().isPrimitive()); // 显示false,因为String 不是基本数据类型 int [] arr = new int[10]; System.out.println(arr.getClass().getComponentType().isPrimitive()); // 显示true,因为int是基本数据类型